perl - apparent strangeness using subroutine with the multiplication operator -
please explain *apparently* inconsistent behaviour me:
use strict; sub { 2 + 2 }; print 2 * a(); # prints: 8 print a() * 2; # prints: 8 print 2 * a; # prints: 8 print * 2; # prints: 4 thanks answers, both helpful - learned lot.
in last example, expression parsed a(*2) calls a glob argument *2 short name of package variable *main::2
if want a parsed function takes no arguments, need declare this:
sub () {2 + 2} then perl parse statement expected. in fact, if write this, perl detect constant function, , inline 4 in every place a have been called.
Comments
Post a Comment