2017-08-26 4 views
-3

私はすべてを理解したと思ったが、私は$ max - >()と$ temp_score = $ max - >()の違いを理解していないと思う。アドレスと後者は実際の値を出力しますか?何かのperlmonksチュートリアルを行っている間

use warnings; 
use strict; 

sub get_max { 
    my $max = $_[0]; 

    return sub { 
     for (@_) { 
      $max = $_ if ! defined $max || $_ > $max; 
     } 
    print "inside of get_max is max currently is $max\n"; 
     return $max; 
    }; 
} 


my $max = get_max(); 
while (<DATA>){ 
    chomp; 
    $max->($_); 
     my $temp_score = $max->(); 
     print ">>>>>>>>>>>>>>>>>>>>>>>>inside while loop, max is $max->()\n"; 
     print ">>>>>>>>>>>>>>>>>>>>>>>>inside while loop, max2 is $temp_score\n"; 
} 

my $high_score = $max->(); 

print "high_score is $high_score\n"; 
__END__ 
90 
91 
92 
87 

答えて

3

なぜ私はあなたがこの行の出力を参照することを想定してい

... 1つのプリントアウトポインタアドレスを行います。それはこの場合

print ">>>>>>>>>>>>>>>>>>>>>>>>inside while loop, max is $max->()\n"; 

変数ではなく$max->()を出力します。これは、文字列の中で変数のみを展開しますが、関数を呼び出さないためです。

>>>>>>>>>>>>>>>>>>>>>>>>inside while loop, max is CODE(0x242cf30)->() 
+0

ありがとう:従って、ストリング->()続く関数ポインタである$maxの値になります。私はこれを試してみたい。私はラップトップでインターネットの近くに行くとすぐにuに戻ります – user3502374

関連する問題