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.
FYI, I ran a benchmark on the different algorithms and
splice @tmp, $_, 0, '|' for reverse 1 .. $#tmp;
is the fastest on small arrays but is the slowest on large arrays while
push @tmp, $_ ? '|' : (), shift @tmp for 0 .. $#tmp;
is second fastest on small arrays and the fastest on large arrays.
And if you want something that is really fast on small arrays then a C
style for loop is the fastest:
for ( my $i = @tmp; --$i; ) {
splice @tmp, $i, 0, '|';
}
John
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>