in reply to constants wont optimize
Drop the "return" keyword:
Also, there's a better way than using eval. You can assign a code reference to a glob:juerd@lanova:~$ perl -MO=Deparse -e'BEGIN { eval "sub foo () { return +42; }" } print foo;' sub BEGIN { eval 'sub foo () { return 42; }'; } print foo; -e syntax OK juerd@lanova:~$ perl -MO=Deparse -e'BEGIN { eval "sub foo () { 42 }" } + print foo;' sub BEGIN { eval 'sub foo () { 42 }'; } print 42; -e syntax OK
*glob = sub () { value };
juerd@lanova:~$ perl -MO=Deparse -e'BEGIN { *foo = sub () { 42 } } pri +nt foo;' sub BEGIN { *foo = sub () { 42 } ; } print 42; -e syntax OK
Juerd
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: constants wont optimize
by patcat88 (Deacon) on Jul 10, 2011 at 17:06 UTC | |
by chromatic (Archbishop) on Jul 11, 2011 at 05:13 UTC |
In Section
Seekers of Perl Wisdom