[Omaha.pm] Push/pop and guranteed order?

Daniel Linder dan at linder.org
Thu Dec 8 14:27:41 PST 2005




Fellow Mongers,

When I push values to an array, am I guranteed that they will be
returned in the same order when I use "foreach"?  Here
is my test code:

#!perl

@CurrentList=();

printf ("Pushing: ");

foreach ("A" .. "Z") {

  push @CurrentList, $_;

  printf ("$_ ");

}

printf ("\nReview:  ");

foreach (@CurrentList) {

  printf ("$_ ");

}

The output of the code looks correct:

Pushing: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 

Review:  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 

If not, is there an easy way to create a FIFO (First In, First Out)
array?  I don't want to resort to creating a key/value pair (i.e.
key/value: 1:A, 2:B, 3:C,...,26:Z) and have to sort on the key.

Dan



- - - - 

"Wait for that wisest of all counselors, time." -- Pericles 

"I do not fear computers, I fear the lack of them." -- Isaac
Asimov 

GPG fingerprint:6FFD DB94 7B96 0FD8 EADF 2EE0 B2B0 CC47 4FDE 9B68
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20051208/93f634fc/attachment.html


More information about the Omaha-pm mailing list