Perl distinction between local variables and variables in my

#! / usr / bin / perl
difference between the local and #my, my local can only be used in a block, but local subroutine can call this block in but not not
# we can use the local global variables provided temporary value, the original value will also go out of scope.
#local defined variable does not exist in the main program, but in the present routine and the subroutine calls the subroutine
$ String = "Hello World!";
Sub PrintRunboo {
  local $ String;
  $ String = "Hello Runoob! ";
  PrintMe (); # Hello Runoob
  Print" $ String \ n-"; # Hello Runoob
}
Sub PrintMe {
  Print" $ String \ n-";
}
Sub printHello {
  Print" $ String \ n-"; # Hello World
}
#calling function
PrintRunboo ();
printHello ();

Guess you like

Origin www.cnblogs.com/shunguo/p/11441657.html