Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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

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.


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

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2016-10-21 16:16 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.