Sorting Multiple Lists
You can sort several lists at the same time:
%countries=('976','Mongolia','52','Mexico','212','Morocco','64','New Zealand','33','France'); @nations=qw(China Hungary Japan Canada Fiji); @sorted= sort values %countries, @nations; foreach (@nations, values %countries) { print "$_\n"; } print "#----\n"; foreach (@sorted) { print "$_\n"; }
This sorts @nations
and the values from %countries
into a new array.
The example also demonstrates that you can foreach
over more than one list value -- each list is processed in turn. How I discovered that
particular trick with Perl is instructive. I just tried it. If you think you should be
able to do something with Perl, try it. Adhere to the syntax and conventions you will be
familiar with from experience, in this case delimiting a list with commas, and try it. I'm
always finding new shortcuts just by experimentation.