Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: How to duplicate every member of an array

by Anonymous Monk
on Jul 28, 2022 at 10:48 UTC ( [id://11145796]=note: print w/replies, xml ) Need Help??


in reply to Re: How to duplicate every member of an array
in thread How to duplicate every member of an array

sounds like homework.
  • Comment on Re^2: How to duplicate every member of an array

Replies are listed 'Best First'.
Re^3: How to duplicate every member of an array -- oneliner
by Discipulus (Canon) on Jul 28, 2022 at 11:20 UTC
    ..if homework a oneliner is needed :D

    perl -MData::Dump -M"5;push @ARGV,reverse @ARGV" -e "push @m,shift,pop while @ARGV;dd @m" a b c

    ("a", "a", "b", "b", "c", "c")

    L*

    PS hello soblanc and welcome to the Monastery and to the wonderful world of Perl!

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      But why not a simple one-liner:

      Win8 Strawberry 5.8.9.5 (32) Thu 07/28/2022 8:22:01 C:\@Work\Perl\monks >perl -MData::Dump -e "my @m = map { ($_) x 2 } @ARGV; dd \@m" a b + c ["a", "a", "b", "b", "c", "c"]


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

      Thank you Discipulus, and thanks everyone for your (quick!) replies :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found