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 :)