Well, if works in that it returns the result of the last expression evaluated. It seems that's what looping constructs should do too. Wouldn't it make sense for this sub x { $_ for 10 } to return 10?Not really. If you're asking my opinion I'd say it should be an error if the sub is called in anything other than a void context. Note the following are also compilation errors...
You're not arguing that they shouldn't be, are you?my $what = (if(1){print "true"}else{print "false"}); sub foo { return (for (1..3) { print $_ }); }
In reply to Re^4: "last expression" quiz
by Anonymous Monk
in thread "last expression" quiz
by fxn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |