Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Case where '( shift @_ )[ 0, 0 ]' returns only one value?

by stevieb (Canon)
on Jan 14, 2019 at 21:19 UTC ( [id://1228546]=note: print w/replies, xml ) Need Help??


in reply to Case where '( shift @_ )[ 0, 0 ]' returns only one value?

All three produce aa on my Perl 5.26.1 running on my Linux Mint workstation. What version of Perl are you running yours under?

spek@scelia ~/scratch $ perl -le '@_ = qw( a b c ); print( ( shift @_ +)[ 0, 0 ] );' aa spek@scelia ~/scratch $ perl -le '@_ = qw( a b c ); @A = ( shift @_ )[ + 0, 0 ]; print @A' aa spek@scelia ~/scratch $ perl -le '@_ = qw( a b c ); @A = ( shift @_ ) +x 2; print @A' aa spek@scelia ~/scratch $ perl -v This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-li +nux

Replies are listed 'Best First'.
Re^2: Case where '( shift @_ )[ 0, 0 ]' returns only one value?
by Paladin (Vicar) on Jan 14, 2019 at 21:47 UTC
    Looks like some kind of change somewhere between 5.18.4 and 5.20.3:
    [~]$ perlbrew exec perl -le '@_ = qw( a b c ); @A = ( shift @_ )[ 0, 0 + ]; print @A' [...] perl-5.22.2 ========== aa perl-5.20.3 ========== aa perl-5.18.4 ========== a perl-5.16.3 ========== a perl-5.14.4 ========== a

      I confirm these findings (on Perl running on Windows at least).

      > berrybrew exec perl -le "@_ = qw( a b c ); @A = ( shift @_ )[ 0, 0 ] +; print @A" perl-5.28.1_64 ============== aa perl-5.20.3_64 ============== aa perl-5.18.4_64 ============== a

        I was going to just edit my post after I got my perlbrew available issue sorted (which I did), but this warrants a new post.

        In 5.10, it produces the result aa that is expected by OP:

        spek@scelia ~/scratch $ perlbrew exec perl -le '@_ = qw( a b c ); @A = + ( shift @_ )[ 0, 0 ]; print @A' perl-5.27.10 ========== aa perl-5.26.1 ========== aa perl-5.20.0 ========== aa perl-5.18.4 ========== a perl-5.10.1 ========== aa

        Going full out, and am installing as many versions as I can to see where it "broke", where it "fixed" and where it "broke" again. Help desired.

        Update: To further, on Unix, it "works" up to 5.12.5, from my testing so far, then goes awry:

        spek@scelia ~/scratch $ perlbrew exec perl -le '@_ = qw( a b c ); @A = + ( shift @_ )[ 0, 0 ]; print @A' perl-5.27.10 ========== aa perl-5.26.1 ========== aa perl-5.20.0 ========== aa perl-5.18.4 ========== a perl-5.16.0 ========== a perl-5.14.4 ========== a perl-5.12.5 ========== aa perl-5.10.1 ========== aa
Re^2: Case where '( shift @_ )[ 0, 0 ]' returns only one value?
by rsFalse (Chaplain) on Jan 14, 2019 at 21:27 UTC
    This is perl 5, version 18, subversion 2 (v5.18.2)

      Ok. I'll do some installs of other versions on Linux and Windows and try to get to the version where it's borked while I finish my work day. On my Windows system I sometimes develop on, with 5.28.1, I get the aa as well:

      c:\repos\berrybrew>perl -le "@_ = qw( a b c ); print( ( shift @_ )[ 0, + 0 ] );" aa c:\repos\berrybrew>perl -le "@_ = qw( a b c ); @A = ( shift @_ )[ 0, 0 + ]; print @A" aa c:\repos\berrybrew>perl -v This is perl 5, version 28, subversion 1 (v5.28.1) built for MSWin32-x +64-multi-thread

        This behavior appears somewhere between versions 5.12.3 and 5.14.4, but a quick scan of the deltas (update: between these versions) shows no justification for it. (Update: All code run under Windows 7.)

        c:\@Work\Perl\monks>perl -wMstrict -le "print 'perl version: ', $]; ;; use Data::Dumper; ;; @_ = qw( a b c ); print( ( shift @_ )[ 0, 0, 0 ] ); ;; @_ = qw( a b c ); my @A = ( shift @_ )[ 0, 0, 0 ]; print Dumper \@A; ;; @A = ( 'x', 'y', 'z' )[ 0, 0, 0 ]; print Dumper \@A; " perl version: 5.012003 aaa $VAR1 = [ 'a', 'a', 'a' ]; $VAR1 = [ 'x', 'x', 'x' ]; perl version: 5.014004 aaa $VAR1 = [ 'a', undef, undef ]; $VAR1 = [ 'x', 'x', 'x' ];
        Version 5.14 is the latest I can access ATM.


        Give a man a fish:  <%-{-{-{-<

      I got the same thing with perl 5, version 18, subversion 1 (v5.18.1) built for x86_64-linux-thread-multi

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found