Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: I am confused by a "Learning Perl" sample showing "unshift"

by harangzsolt33 (Chaplain)
on Jan 24, 2021 at 20:03 UTC ( [id://11127396]=note: print w/replies, xml ) Need Help??


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.
  • Comment on Re: I am confused by a "Learning Perl" sample showing "unshift"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found