in reply to I am confused by a "Learning Perl" sample showing "unshift"
This shouldn't be confusing at all. The unshift() function in JavaScript, Perl's sister language, works the same way. When you want to unshift more than one item at a time, it grabs them as one and inserts them in front of the array in the same order as you put them. This is useful, because if we consider a real-life scenario where you want to pack some data, and the First name must come first, followed by Last Name and then the middle name, you could do something like : unshift(@PACKAGE, @NAMES); then the address, where the first element of address holds the house number, followed by street, city, state, zip code, in that order, the unshift method will not mess up the order. It will simply insert these items into the array just the way they appear in the other array: unshift(@PACKAGE, @ADDRESS); unshift(@PACKAGE, @DELIVERY_DATE_SELECTED); So, let's say you have a DATE array which contains the year first, followed by month and day. If you unshift that, the order will remain the same in the array, which is logical and that's how it should work.
|