> I need to create a hash with fixed elements and print all elements. 

I think that people keep missing this when they send their answers.
They're telling you how to print the hash, which is helpful, but not how
to keep the sequence of items.  Because of the way that hashing is done,
no hash is fixed.  If it were fixed, then it'd lose most of it's
efficiency.

When you call the keys function on a hash, it just returns a list of the
keys in no specific (or reliable) order.  Calling the sort function just
sorts them alphabetically.

In order to preserve sequence, you could do something
not-so-easy-to-read, like this.

use strict;
my @color_array = (
                   ["sky", "blue"],
                   ["grass", "green"],
                   ["apple", "red"]
                   );

foreach (0..$#color_array) {
    print "$color_array[$_]->[0]: $color_array[$_]->[1]\n";
}

print "Pushing a yellow sun into the array...\n";
push @color_array, ["sun", "yellow"];

foreach (0..$#color_array) {
    print "$color_array[$_]->[0]: $color_array[$_]->[1]\n";
}


This code should work (I actually tested it - imagine that) - it isn't
exactly intuitive or easy to use, but it preserves the sequence, and you
can push items onto it later.

====================
Brian Arnold
[EMAIL PROTECTED]


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to