in reply to How much can a function know about the context in which it is called?
sub test { print(defined(wantarray)?1:0, " "); print(wantarray?1:0, "\n"); } test(); # 0 0 $a = test(); # 1 0 @a = test(); # 1 1
sub function { my $rv = "Hello World"; if (defined wantarray) { return $rv; } else { print("$rv\n"); return; } } function(); # Hello World my $greet = function(); print("[$greet]\n"); # [Hello World]
|
|---|