qq78707 发表于 2018-8-31 08:39:27

perl的老地方$_

  foreach 省略了控制变量,Perl就使用他的老地方变量$_代替。
  # less LaoDiFang.pl
  #!/usr/bin/perl
  foreach (1..10) {
  print "I can count to $_!\n";
  }
  # perl LaoDiFang.pl
  I can count to 1!
  I can count to 2!
  I can count to 3!
  I can count to 4!
  I can count to 5!
  I can count to 6!
  I can count to 7!
  I can count to 8!
  I can count to 9!
  I can count to 10!
  # less LaoDiFang1.pl
  #!/usr/bin/perl
  $_ = "Hello LaoDiFang \$_";
  print;
  print "\n";
  # perl LaoDiFang1.pl
  Hello LaoDiFang $_
  打印不指定变量时就答应 $_

页: [1]
查看完整版本: perl的老地方$_