perl in private variables

! # / usr / bin / perl
Sub g_print {
Print "the X-$ \ the n-";
}
  #my local variables are called private.
  test_my {Sub
  My X = $. 11; #my variables defined only in (between two {}) in the block, can not be passed inwardly
  print "call-my $ x \ n"; # 11, the nearest principles
  g_print; #my parameters can not be passed inwardly, so that the output or 9
}

  test_local {Sub
  local X = $ 20 is; #local also private variables, but the difference is that with my, can pass inwardly local
  Print "Call-local $ X \ n-"; # 20 is
  g_print; # 209
}

X =. 9 $;
test_my;
test_local;
Print $ X;
#my variables: the variables can only be seen in this layer module
#local variables: The function of this layer and the underlying layer can be seen variables

Guess you like

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