more useful options | |
PerlMonks |
Re: What is the difference between a list and an array?by belg4mit (Prior) |
on Dec 11, 2001 at 09:09 UTC ( [id://130864]=note: print w/replies, xml ) | Need Help?? |
Arrays and hashes can both be used as lists, witness:
Within each code block both calls to foo pass the same values; @_(the parameters list) will be the same. NOTE: It is luck that the first works, as it relies upon the particular key/value pairs and how the current implementation of hashes in perl works. Basically an array is an actual thing that lives somewhere and has an address (you can get a glob for it, you can use a reference to it), but that is not so for a list. UPDATE: Modified code to ensure hash order prompted by dmmiller2k's reply. Which of course makes the comparison a little less clear since it uses slices. Added a second code block to reclarify UPDATE I am an idiot. The sliced version only returned the values. And it did in fact work as advertised to begin with. It was just lucky that it did so. Added the NOTE, I really do understand this, but apparently I'm not very good at explaining it with code ;-)
--
In Section
Meditations
|
|