in reply to How to get the values from XML/Text file in a specific order?

You can also use sort and keys together, e.g.

my %hash = ( "monkey" => "three", "cobra" => "dance" ); foreach my $key (sort keys %hash) { print "$key is " . $hash{$key} . "\n"; } cobra is dance monkey is see

The sort verb is applied to the result of the keys verb as applied to %hash.   Therefore, $key will contain each of the hash-keys, in alphabetical order, and this is then used to retrieve the values.   AFAIK, each() can be relied to return keys in a particular order only when the variable is tied to certain types of indexed files.

Certain cases of sorting can also be specified in an XSLT stylesheet, which is language-independent and can be applied to any XML file e.g. in a browser.   See here.