1 / 20

Perl - Advanced

Perl - Advanced. More Advanced Perl Functions Control Structures Filehandles Process Management. Perl Functions. Function – Sub routine Definition Keyword “sub” – Definition of a sub routine Name of the routine “subname” Block Of statements {…} sub subname { statement_1 ;

alban
Download Presentation

Perl - Advanced

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Perl - Advanced More Advanced Perl • Functions • Control Structures • Filehandles • Process Management

  2. Perl Functions • Function – Sub routine Definition • Keyword “sub” – Definition of a sub routine • Name of the routine “subname” • Block Of statements {…} sub subname { statement_1; statement_2; statement_3; }

  3. Invoking a User Function • We invoke a user function from within an expression by following the subroutine name with parentheses. • say_what(); or • &say_what(); • A subroutine can invoke another subroutine, and that subroutine can in turn invoke another subroutine, and so on.

  4. Return Values

  5. Example on Arguments sub add { $sum = 0; # initialize the sum foreach $_ (@_) { $sum += $_; # add each element } return $sum; # last expression evaluated: sum of all elements } • We invoke the above function by typing add($a, $b, …) where inside the parentheses we put as many variables as we like. • The @_ variable is privateto the subroutine. This also means that a subroutine can pass arguments to another subroutine without fear of losing its own @_ variable; The nested subroutine invocation gets its own @_ in the same way.

  6. Control Structures

  7. Examples of true and false interpretations

  8. Control Structures

  9. Control Structures

  10. Control Structures

  11. Control Structures

  12. Filehandles

  13. Filehandles

  14. Filehandles example

  15. Process Management

  16. Using Processes as Filehandles

  17. Using Processes as Filehandles

  18. Summary of Process Operations

  19. Perl versus C

  20. Exercises

More Related