in reply to How to sort Hashes of Hashes and print results in a file
#!usr/bin/perl -w use strict; # a HoH my %people = ("Fred Jones" => {"AGE" =>45, "SALARY" => 90000}, "Joe Smith" => {"AGE" =>32, "SALARY" => 36400}, "Mary Arne" => {"AGE" =>29, "SALARY" => 66122}, "Ted Carney" => {"AGE" =>56, "SALARY" => 100000}, ); foreach my $key (sort keys %people) { print " $key $people{$key}->{'AGE'} $people{$key}->{'SALARY'}\n"; + } print "\nThis is the version using a hash slice\n"; foreach my $key (sort keys %people) { print " $key @{$people{$key}}{('AGE', 'SALARY')} \n"; } __END__ Prints: Fred Jones 45 90000 Joe Smith 32 36400 Mary Arne 29 66122 Ted Carney 56 100000 This is the version using a hash slice Fred Jones 45 90000 Joe Smith 32 36400 Mary Arne 29 66122 Ted Carney 56 100000
|
|---|