Undefined variables in Perl subroutines -


I'm new to Perl and would like some help in understanding subroutine. In sub-routine, is it the case that some variables will always remain undefined? Is it because the variables in subroutines are private? And so if I wanted to define then, then the undetermined variable was said, how would I do this? Thanks in advance. Variants are not private in Perl, but they can have a limited scope such as when they < Code> My is declared inside a subroutine The arguments of the subroutine are stored in the variable @_ .

  do_stuff ($ foo, $ bar); Sub-do_stuff {my ($ first, $ sec) = @_; # Direct Assignment Print "First: $ First, Second: $ sec \ n"; }  

{...} , which means That they are protected, and when they leave the removal block, then they go out of the scope.

Arguments of sub-routine can also be accessed from the sourcing function shift and pop , which is commonly seen in the Perl code:

  sub-do_stuff {my $ first = shift; My $ sec) = shift;  

It does the same thing, except that it also removes the elements from the @_ array.

Read more:


  • Comments

    Popular posts from this blog

    ios - How do I use CFArrayRef in Swift? -

    eclipse plugin - Run java code error: Workspace is closed -

    c - Error on building source code in VC 6 -