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

..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.

Replies are listed 'Best First'.
Re^4: How to duplicate every member of an array -- oneliner
by AnomalousMonk (Archbishop) on Jul 28, 2022 at 12:30 UTC

    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:  <%-{-{-{-<

Re^4: How to duplicate every member of an array -- oneliner
by soblanc (Acolyte) on Jul 28, 2022 at 14:05 UTC
    Thank you Discipulus, and thanks everyone for your (quick!) replies :)