in reply to Re^5: Syntax for Hashes of Hashes
in thread Syntax for Hashes of Hashes
And again, here is the data file:#!/usr/bin/perl -w use strict; my %myHash = (); my @names; open (INFO,"<info.txt"); while (<INFO>) { my ($name,$species,$gender,$age,$hairColor) = split /,/,$_; push @names,$name; $myHash{ $name } = {}; addValues( $myHash{ $name },\$name,\$species,\$gender,\$age,\$hair +Color); } print "From outside the subroutine:\n"; foreach my $key ( @names ) { print "Key:\t$key\n"; print $myHash{$key}{'name'}, "\n"; } close (INFO); sub addValues { my ( $hashNameRef,$namRef,$speRef,$genRef,$ageRef,$hairColRef ) = +@_; $hashNameRef = { name => $$namRef, species => $$speRef, gender => $$genRef, age => $$ageRef, hairColor => $$hairColRef }; print "$$hashNameRef{'name'}\t$$hashNameRef{'species'}\t$$hashName +Ref{'gender'}\t$$hashNameRef{'age'}\t$$hashNameRef{'hairColor'}\n"; }
Am I doing something wrong? I don't know, man! I tried a lot of syntax variants, but no go. I always get that error message.Tony,human,male,47,gray Mark,human,male,48,brown Tyler,dog,male,11,brown Anthi,human,female,39,black Spud,cat,male,14,white Erica,human,female,23,blonde
|
---|