Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

The mystery of $->[1]

by hurricup (Pilgrim)
on Jul 11, 2015 at 19:52 UTC ( #1134310=perlquestion: print w/replies, xml ) Need Help??

hurricup has asked for the wisdom of the Perl Monks concerning the following question:

Encountered an interesting piece of code inside of ExtUtils::Constant::Base:

my $l = ref $a eq 'ARRAY' ? ($a->[0] || $->[1]) : $a;
The question is about $->1. According to perlvar $- is a The number of lines left on the page of the currently selected output channel. And what are we doing here? Comparing lines number with anonymous array? What the..?

Replies are listed 'Best First'.
Re: The mystery of $->[1]
by kcott (Bishop) on Jul 11, 2015 at 20:59 UTC

    G'day hurricup,

    ++ Good catch!

    The code itself parses as legal Perl:

    $ perl -MO=Deparse,-p -e 'my $l = ref $a eq "ARRAY" ? ($a->[0] || $->[ +1]) : $a;' (my $l = ((ref($a) eq 'ARRAY') ? ($a->[0] || ($- > [1])) : $a)); -e syntax OK

    And, as you can see, your analysis is correct: '$-' is being compared with '[1]'.

    There's actually two adjacent lines like that in the source code:

    # Deal with the case of an item actually being an array ref to 1 o +r 2 # hashrefs. Don't assign to $a or $b, as they're aliases to the or +ignal my $l = ref $a eq 'ARRAY' ? ($a->[0] || $->[1]) : $a; my $r = ref $b eq 'ARRAY' ? ($b->[0] || $->[1]) : $b;

    I suspect those should be:

    my $l = ref $a eq 'ARRAY' ? ($a->[0] || $a->[1]) : $a; my $r = ref $b eq 'ARRAY' ? ($b->[0] || $b->[1]) : $b;

    although, I haven't delved deeply enough into the code to say for certain.

    I suggest you raise a bug report for this.

    -- Ken

      Thought about typo, but last my "discoveries" shown that I'm John Snow in Perl :) And thought it may be some unknown magic.

      Will report a bug.

Re: The mystery of $->[1]
by LanX (Archbishop) on Jul 11, 2015 at 20:56 UTC
    Obviously a typo ('a' missing), which isn't caught by the parser because of your wtf interpretation.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

    PS: you might want to report the bug.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2019-10-14 00:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?