in reply to Re: Array confusion.
in thread Array confusion.

A slightly simplified version:

@a = 'a'..'z';; @b = sub{ map pop, @_ }->( @a );; print @b;; z y x w v u t s r q p o n m l k j i h g f e d c b a

Or even just:

@c = map pop @a, @a;; print @c;; z y x w v u t s r q p o n m l k j i h g f e d c b a

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Array confusion.
by johngg (Canon) on Feb 15, 2017 at 11:44 UTC
    @c = map pop @a, @a;;

    Much simpler, true, but destructive if that is a concern.

    johngg@shiraz:~/perl > perl -Mstrict -Mwarnings -E ' my @arr = ( q{a} .. q{z} ); my @rev = map pop @arr, @arr; say qq{@arr}; say qq{@rev};' z y x w v u t s r q p o n m l k j i h g f e d c b a

    Cheers,

    JohnGG

      but destructive if that is a concern.

      True. Then:

      @a = 'a'..'z';; unshift @d, $_ for @a;; print @d;; z y x w v u t s r q p o n m l k j i h g f e d c b a print @a;; a b c d e f g h i j k l m n o p q r s t u v w x y z

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.