Perl - PowerPoint PPT Presentation

About This Presentation
Title:

Perl

Description:

Arguments are not listed in declaration. May use a return statement ... Parens may be omitted if declaration has already been seen ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 8
Provided by: royl2
Learn more at: https://www.cse.fau.edu
Category:
Tags: parens | perl

less

Transcript and Presenter's Notes

Title: Perl


1
Perl
  • Functions

2
Defining Functions
  • sub subroutine_name
  • stmt1 stmt2
  • Arguments are not listed in declaration
  • May use a return statement
  • If no return statement, value of last expression
    is returned
  • Can return scalar, array, or hash

3
Calling Functions
  • Called by
  • sub_name(arg1, arg2, )
  • Parens may be omitted if declaration has already
    been seen
  • Arguments are available in called function as
    entries in array _at__

4
Sample Function
  • sub max
  • (a, b) _at__
  • a gt b ? a b
  • Puts args into variables
  • Returns larger if they are numbers

5
Array and Hash Arguments
  • Can only pass one array or hash as an argument
    unless you know the size
  • Args are flattened
  • (_at_a, _at_b) _at__ all in _at_a
  • Can precede array or hash by a fixed number of
    scalars but
  • (a, _at_b, c) _at__
  • wont work

6
Scope
  • my(a)
  • my c, _at_e
  • Declares local variable with scope of block
    (including function) or loop (in control
  • Parentheses are optional

7
Strict
  • use strict
  • Directive requires
  • Declare all variables
  • Declare all functions before first use
Write a Comment
User Comments (0)
About PowerShow.com