in reply to Hash of hashes syntax
I'd probably make it somewhat cleaner, like so:my %hash_of_hashes; while (<UNITFILES>) { my @unitfiles_field = split /,/; # this is just an autogen number my $record = $unitfiles_field[0]; my %unitfiles_hash = ( lastname => $unitfiles_field[1], firstname => $unitfiles_field[2], DOB => $unitfiles_field[7], funding => $unitfiles_field[18], URNo => $unitfiles_field[15], Photo_permission => $unitfiles_field[14], ); # add this hash to the hash-of-hashes: $hash_of_hashes{$record_no} = \%unitfiles_hash; }
Or I might even consider the following. (TIMTOWTDI!)my %hash_of_hashes; while (<UNITFILES>) { my @f = split /,/; $hash_of_hashes{$f[0]} = { lastname => $f[1], firstname => $f[2], DOB => $f[7], funding => $f[18], URNo => $f[15], Photo_permission => $f[14], }; }
my %hash_of_hashes; while (<UNITFILES>) { my %h; (my $rn, @h{ qw(lastname firstname DOB funding URNo Photo_permission) }) = (split /,/)[0,1,2,7,18,15,14]; $hash_of_hashes{$rn} = \%h; }
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hash of hashes syntax
by bwana147 (Pilgrim) on Mar 19, 2003 at 08:41 UTC | |
by Enlil (Parson) on Mar 19, 2003 at 09:19 UTC | |
by Chmrr (Vicar) on Mar 19, 2003 at 09:24 UTC |