in reply to running backwards on a hash
Firstly, hash structures by their nature are unordered lists of scalars - There is no intrinsic order to the index keys which are returned via keys or each. It is discussed in the perldata man page that while a hash may be initialised in a particular order it is no guarentee that iteration of the hash index returns elements in this order - This is also discussed in the perlfunc:keys man page.
If you are wanting a specific order in the hash indices or values returned in a list, you will need to employ the perlfunc:sort function. eg.
# iterate by sorted list of hash keys foreach my $key (sort keys %hash) { ... } # iterate by sorted list of hash values foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { ... }
If you are wanting to reverse this sorted order of hash keys or values, you simply need to employ the perlfunc:reverse function. eg.
# iterate by reverse sorted list of hash keys foreach my $key (reverse sort keys %hash) { ... } # iterate by reverse sorted list of hash values foreach my $key (reverse sort { $hash{$b} <=> $hash{$a} } keys %hash) +{ ... }
perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'
|
|---|