note
demerphq
<em>A good way to get to know splice better is to re-implement push, pop, unshift and shift with it.</em><p>
Uhm, or you could just read the docs :-)
<code>
D:\Development>perldoc -f splice
splice ARRAY,OFFSET,LENGTH,LIST
.....
The following equivalences hold (assuming "$[ == 0"):
push(@a,$x,$y) splice(@a,@a,0,$x,$y)
pop(@a) splice(@a,-1)
shift(@a) splice(@a,0,1)
unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
$a[$x] = $y splice(@a,$x,1,$y)
</code>
<em>A good way to get to know substr better is to create push/pop/unshift/shift functions for strings.</em><p>
Well.... Once you know how to implement splice using susbtr you dont <b>need</b> to implement push/pop/unshift or shift, but its true it might be a good exercise.
Personally would suggest taking that thought a step further and reimplement [cpan://Tie::CharArray], by the time you are done if you dont understand Tie's, Array implementation, Splice Implementation and Substr implementation then I would say theres something very wrong... (either with the individual or the code ;-) Oh and it probably is a good idea because you can use the CPAN module for a proper code comparison and review afterward.<p>
Thats what I did to learn Tie the first time anyway... :-)
<P>
Yves / DeMerphq<br>
--- <BR>
Writing a good benchmark isnt as easy as it might look.
156829
156851