Doctrin has asked for the wisdom of the Perl Monks concerning the following question:
I wanna have this: 1!2*3?4 Surely, I could make something like:my @arrOfJoiners = ('!','*','?'); my @arrToJoin = (1,2,3,4);
But, is there a smarter way to do it using, say, "join" ? Maybe, even one-liner?.. Thanks in advance. ====UPD==== Oh, looks like I got it:my @arrOfJoiners = ('!','*','?'); my @arrToJoin = (1,2,3,4); my $s; for my $arrElem (@arrToJoin) { $s .= $arrElem . (shift @arrOfJoiners); } print $s;
Thanks, I think this would be fine.$s = join "", (map {$_ . (shift @arrOfJoiners)} @arrToJoin);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Joining array with elements of another array
by tobyink (Canon) on Mar 18, 2013 at 16:12 UTC | |
|
Re: Joining array with elements of another array
by toolic (Bishop) on Mar 18, 2013 at 15:49 UTC | |
by davido (Cardinal) on Mar 18, 2013 at 16:07 UTC | |
|
Re: Joining array with elements of another array
by Anonymous Monk on Mar 18, 2013 at 15:23 UTC |