Jay Savage wrote:
> On 7/20/05, Bryan R Harris <[EMAIL PROTECTED]> 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 would do something like:
> 
>    unshift(@ar, $_ == 1 ? pop @ar : (pop @ar, '|')) foreach [EMAIL PROTECTED];
> 
> map might be faster; benchmark it.

You can simplifiy that a bit:

unshift( @ar, $_ ? (pop @ar, '|') : pop @ar ) for 0 .. $#ar;

Which also leads to:

unshift @ar, (pop @ar, $_ ? '|' : ()) for 0 .. $#ar;

Or also:

push @ar, ($_ ? '|' : (), shift @ar) for 0 .. $#ar;



John

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to