tneff@bfmny0.UU.NET (Tom Neff) (02/26/90)
Actually 'push' and 'pop' are the wrong operators for array inserts and deletes, because as Larry says they are slightly counterintuitive, and require useless information. The right operators are 'shift' and 'unshift'. Imagine an array @arr = (tom,dick,harry,jane,sally,bambi,tammy,faye); Now if you want to take things out of the middle or put them in, you don't CARE about the stuff to the left; only the tail of the array (after your operation) moves around. Well, that's shift and unshift. Despite Larry's misgivings I think the @slice notation is clearest here. The one drawback to slice notation as it exists today is the lack of a way to say "N through last" without rewriting the array name. Omitting the left or right side of a range .. operator in a slice context should mean "$[" or "$#arr" respectively. So we get $elt = shift(@arr[$n..]); unshift(@arr[$m..], $elt1, $elt2...) Now that is elegant and carries no useless information.