| [reply] [Watch: Dir/Any] [d/l] |
The -w switch seems to be unnecessary, and the -l switch seems only to assure that a newline is spit out at the end of the print. If you can do without that, and eliminate all unnecessary whitespace, you can save four more keystrokes:
perl -e'print[]+0'
The principle is this: [] creates an anonymous array reference. Evaluated in scalar context, it would appear as (for example) "ARRAY(0x155513c)." The "+0" operation causes the numeric value of the string "ARRAY(0x155513c)" to be added to zero, resulting in the non-numeric portion of "ARRAY(0x155513c)" being dropped. Finally, print automatically represents the hex number in base ten. The result (on my computer) is "22368572", which happens to be the base-10 version of the hex number "0x155513c".
| [reply] [Watch: Dir/Any] [d/l] [select] |
I think you mean "string context", not "scalar context". Scalar context per se doesn't turn a reference to anything.
And the numeric value of a string "ARRAY(0x155513c)" is zero:
perl -e "$x = []; print qq{$x}+0"
In the original case the reference is evaluated in numerical context, not first in string and then numerical. And in numerical context reference evaluates to the address.
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
| [reply] [Watch: Dir/Any] [d/l] |
The -w switch seems to be unnecessary, and the -l switch seems only to
assure that a newline is spit out at the end of the print.
just commenting on that:
when i'm coding on commandline i always use -wle now. it's
just automatically. without that i would have been bitten so often from a
missed warning. and -l is just so convenient.
also if i copy and paste commandline code from others i find it annoying if
it doesn't contain -wl
| [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] |