jatinpatel has asked for the wisdom of the Perl Monks concerning the following question:
My input file looks like this:$hash = {A1 => 'AB', A2 => '', A3 => ''}; # read info from file open (INFH,$myfile); create_array(*INFH, $hash, \$arry_hash); for $i (0 .. $#arry_hash) { for $key (keys %{$arry_hash[$i]}) { print "key :$key = $arry_hash[$i]->{$key} "; } print "}\n"; } sub create_array { my $FH = shift; my $rec_hash = shift; my $arry_ref = shift; while (<$FH>) { $tmp_hash = $rec_hash; for $field (spilt ',') { ($key, $value) = split /=/, field; chomp($value); $tmp_hash->{$key} = $value; } push @$arry_ref, {%tmp_hash}; } close ($FH); }
How can I access the value of A1 and A2 and loop through the array.A2=ABCD,A3=0123 A2=QWER,A3=4567 A2=ASDF,A3=7890
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I access array of hashes reference
by ikegami (Patriarch) on Aug 07, 2007 at 19:42 UTC | |
|
Re: How do I access array of hashes reference
by thezip (Vicar) on Aug 07, 2007 at 19:45 UTC |