Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: concatenating the array elements
by Zaxo (Archbishop) on May 26, 2005 at 11:25 UTC

    Are you sure you want an array for the result? Your description and example look more like a string: $concat = join ',', map {"!$_"} @array1;

    If you really mean the array,

    @array2 = map {"!$_,"} @array1; chop $array2[-1];
    That's the first time I've found chop useful ;-)

    After Compline,
    Zaxo

Re: concatenating the array elements
by wiredrat (Acolyte) on May 26, 2005 at 11:31 UTC
    Hi, It's not clear what you really want. @array2 = !blue,!white,!yellow is not an array. May be you mean that you want $list = "!blue,!white,!yellow"; or @array2 = ( "!blue", "!white", "!yellow" ); The first can be done with:
    $list = join ',', map { $_ = "!" . $_; } @array1;
    But, probably you prefer:
    foreach my $t (@array1) { push @array2, "!" . $t; ; print join ",", @array2;
    Hope this help you :)