tachyon has asked for the
wisdom of the Perl Monks concerning the following question:
Over in Obfuscation this point came up:
C:\>type test.pl
use, strict
C:\>perl -MO=Deparse test.pl
syntax error at test.pl line 1, near "use,"
test.pl had compilation errors.
C:\>test.pl
C:\>type test.pl
use => strict
C:\>perl -MO=Deparse test.pl
'???', '???';
test.pl syntax OK
C:\>
Now this is of course pretty arcane but what is the difference and why?
Re: When is => ne , (warning rather arcane and possibly totally useless) by BrowserUk (Pope) on Jul 22, 2004 at 04:28 UTC |
P:\test>perl -e"'fred' => 1;"
A hash element pair in a void context?
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
| [reply] [d/l] |
|
perl -MO=Deparse -e "'moo', 'oom', 'zoop'"
'???', '???', '???';
-e syntax OK
| [reply] [d/l] |
|
| [reply] |
Re: When is => ne , (warning rather arcane and possibly totally useless) by Zaxo (Archbishop) on Jul 22, 2004 at 04:30 UTC |
I suspect that use is stringified by a fat comma before it is recognised as a keyword, I haven't yet figured out how to test that theory.
| [reply] |
|
Yes, that's exactly what's happening:
% perl -le 'print for f(); sub f {use => strict}'
use
strict
| [reply] [d/l] |
Re: When is => ne , (warning rather arcane and possibly totally useless) by edan (Curate) on Jul 22, 2004 at 06:37 UTC |
Perhaps I'm just being thick, and there is something much more subtle going on here that I am missing, but isn't that exactly the documented difference between ',' and '=>'? From perldoc perlop (emphasis mine):
The => digraph is mostly just a synonym for the comma operator. It's useful for documenting arguments that come in pairs. As of release 5.001, it also forces any word to the left of it to be interpreted as a string.
So the statement 'use => strict' is a 2-element list in void context, whereas using a comma allows 'use' to be interpreted as a keyword, thus the syntax error...
| [reply] |
|
perl -MO=Deparse -e "'use', 'strict'"
'???', '???';
-e syntax OK
perl -MO=Deparse -e "'use'=> 'strict'"
'???', '???';
-e syntax OK
| [reply] [d/l] |
Re: When is => ne , (warning rather arcane and possibly totally useless) by dragonchild (Archbishop) on Jul 22, 2004 at 12:43 UTC |
I think part of the boggling has to do with the fact that 'strict' is a legal bareword if strictures are off. I had to think through that one when I looked at this one. (Nice conundrum, btw. ++!) You see "use strict" in some fashion and that bit is flipped in your head, regardless of the fact that the mess you're considering is the "use strict" declaration itself. So, I was applying strictures (specifically strict 'refs') without truly verifying that strictures were in force.
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
| [reply] |
|
|