Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: @_ still mystifies me

by Ovid (Cardinal)
on Jun 01, 2002 at 17:36 UTC ( #170930=note: print w/ replies, xml ) Need Help??


in reply to @_ still mystifies me

A great way of figuring how Perl parses a particular piece of code is to use the B::Deparse module. That will attempt (usually successfully) to deparse your code and make its meaning more clear. To run it against a program, you would do something like this:

perl -MO=Deparse someprog.pl

The output will be Deparse's interpretation of what the code really does. Usually, the result is not too far off of what you have. In this case, I ran Deparse against you snippet and the result surprised me. Not in what it was saying to do, but in how it said it. In any event, it was much more clear. This should help you in the future -- I hope:

$ perl -MO=Deparse -e 'my @lexlist = @_ or sort keys %lexicon' sort keys %lexicon unless my(@lexlist) = @_;

So, as you can see, that parsed completely differently from your expectations. Hope this helps.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


Comment on Re: @_ still mystifies me
Select or Download Code
Re: Re: @_ still mystifies me
by danger (Priest) on Jun 01, 2002 at 17:49 UTC

    I'm glad Ovid (++) mentioned the Deparse module, but be aware that different options can affect the output:

    # no options: $ perl -MO=Deparse -e 'my @lexlist = @_ or sort keys %lexicon' sort keys %lexicon unless my(@lexlist) = @_; #--- # using -x7 (level 7 expands code into equivelant logical constructs # using &&, ?:, and do{}) -- (giving us back nearly the original) $ perl -MO=Deparse,-x7 -e 'my @lexlist = @_ or sort keys %lexicon' my(@lexlist) = @_ or sort keys %lexicon; #--- # however, using -p (to fully parenthesize) can often help expose # such problems as well: $ perl -MO=Deparse,-p -e 'my @lexlist = @_ or sort keys %lexicon' ((my(@lexlist) = @_) or sort(keys(%lexicon)));

    It is sometimes useful to explore the output of Deparse with various options applied.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2014-07-25 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls