Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

When is => ne , (warning rather arcane and possibly totally useless)

by tachyon (Chancellor)
on Jul 22, 2004 at 04:24 UTC ( #376462=perlquestion: print w/ replies, xml ) Need Help??
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?

cheers

tachyon

Comment on When is => ne , (warning rather arcane and possibly totally useless)
Download Code
Re: When is => ne , (warning rather arcane and possibly totally useless)
by BrowserUk (Pope) on Jul 22, 2004 at 04:28 UTC

    When it's the same as

    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

      There is no "hash" involved here. It's merely a list.

      perl -MO=Deparse -e "'moo', 'oom', 'zoop'" '???', '???', '???'; -e syntax OK

        I've been reading to much Perl 6 stuff where Pairs are distinct entities. Your right. It's just a 2 element list in a void context which is being optimised away. Hence the '???'.


        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
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.

    After Compline,
    Zaxo

      Yes, that's exactly what's happening:
      % perl -le 'print for f(); sub f {use => strict}' use strict
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...

    --
    edan

      I agree. When the string is made explicit, it does not change the result:

      perl -MO=Deparse -e "'use', 'strict'" '???', '???'; -e syntax OK perl -MO=Deparse -e "'use'=> 'strict'" '???', '???'; -e syntax OK
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://376462]
Approved by Zaxo
Front-paged by bunnyman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-12-28 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls