Yet another solution: composite key...
while (<INFILE>) { my $key = $_; my ($num, $name) = ($_ =~ /(\d+)\s*[,]\s*(.*?)\s*$/); my %rec = { productnumber => $num, productname => $name, }; $product{$key} = \%rec; }
Now you can sort asciibetically keys %product, or if need be do something fancier by sorting on the fields in the records, without any changes to your basic data structure. You can also add in additional fields to the records (price, whatnot), again without changing the fundamental way that you structure your data.
for(unpack("C*",'GGGG?GGGG?O__\?WccW?{GCw?Wcc{?Wcc~?Wcc{?~cc' .'W?')){$j=$_-63;++$a;for$p(0..7){$h[$p][$a]=$j%2;$j/=2}}for$ p(0..7){for$a(1..45){$_=($h[$p-1][$a])?'#':' ';print}print$/}
In reply to Re: 2 dimensional array sorting...
by jonadab
in thread 2 dimensional array sorting...
by Soko
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |