in reply to Surprised by join
You can even change the separator depending of its neighbors, which are supplied as arguments to the code block.sub myjoin (&@) { my $sub = shift; my $res = $_[0]; for my $i (1 .. $#_) { $res .= $sub->($_[$i-1], $_[$i]) . $_[$i]; } $res; } my @a = (':','',':',''); my $i=0; print myjoin { $a[$i++] } 0,1,0,1; # Right now
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Surprised by join
by EdwardG (Vicar) on Jun 08, 2004 at 13:47 UTC | |
by eserte (Deacon) on Jun 08, 2004 at 14:11 UTC | |
|
Re^2: Surprised by join
by Roy Johnson (Monsignor) on Jun 08, 2004 at 16:53 UTC | |
by EdwardG (Vicar) on Jun 08, 2004 at 19:10 UTC |