#!/usr/bin/perl
#my 和 local的区别,my local都只能在一个block中使用,但是local可以在该block的子程序中调用 但是没有不可以
#我们可以使用 local 为全局变量提供临时的值,在退出作用域后将原来的值还回去。
#local 定义的变量不存在于主程序中,但存在于该子程序和该子程序调用的子程序中
$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();

相关文章:

  • 2022-01-02
  • 2022-01-02
  • 2022-12-23
  • 2022-02-09
  • 2021-07-20
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-01
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案