John W. Krahn wrote: > John W. Krahn wrote: >>Bryan R Harris wrote: >>>I'd like to turn array @tmp from: >>> >>> (1,2,3) >>> >>>to >>> >>> (1,"|",2,"|",3) >>> >>>I'm using: >>> >>> @tmp = split(' ', join(" | ", @tmp)); >>> >>>... but it seems like a waste to create a string and then split it back up >>>again. >>I can think of two ways to do it: >> >>splice @tmp, $_, 0, '|' for reverse 1 .. $#tmp; >> >> >>@tmp = ( map( ($_, '|'), @tmp[ 0 .. $#tmp - 1 ] ), $tmp[ -1 ] ); > > Another way to do it: > > @tmp = splice @{[ map( ('|', $_), @tmp ) ]}, 1;
Or just using a list: @tmp = ( map +( $_, '|' ), @tmp )[ 0 .. 2 * $#tmp ]; John -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>