Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: NEWBIE Brain Teaser #2, by nysus

by koolade (Pilgrim)
on Apr 16, 2001 at 06:58 UTC ( #72755=note: print w/ replies, xml ) Need Help??


in reply to NEWBIE Brain Teaser #2, by nysus

This was a good exercise. My biggest hurdle was figuring out why $_ held the value 2 and @_ contained qw(nothing nothing) rather than qw(alpha omega). After a bit of searching I think I found the answer.

I tracked down information on the qw operator and found this in the perlop manpage:

qw// is exactly equivalent to split(' ', q/STRING/); This equivalency means that if used in scalar context, you'll get split's (unfortunate) scalar context behavior...

So read the documentation on split and found:

If not in list context, returns the number of fields found and splits into the @_ array.

So is that pretty much answer? Is there any more magic to it?


Comment on Re: NEWBIE Brain Teaser #2, by nysus
Select or Download Code
qw// in Perl 5.6
by Eureka_sg (Monk) on Apr 16, 2001 at 07:26 UTC

    I believe that qw// no longer use split in 5.6. Instead, it's using the comma-operator. As a result, you are just trying to assign a list to a scalar. Thus, $_ will just hold 'nothing' and the answer for part c is "In the beginning there was alpha, in the end there will be omega."

    Disclaimer: I don't have 5.6 installed, so the above is pure speculation. Pls correct me if I'm wrong. : )

      Actually, with version 5.005, the script yields: "In the beginning there was nothing, in the end there will be nothing."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://72755]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-12-25 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (163 votes), past polls