Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Array confusion.

by BrowserUk (Patriarch)
on Feb 14, 2017 at 23:51 UTC ( [id://1182034]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

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

    No recent polls found