General answer : References quick reference.
More specific answer:
$data{$formname} is an entry in a hash. The wrapping of the @{ ... } around it indicates that this hash entry is a reference to an array. What's being pushed onto the array is an anonymous hash (reference to a hash with no name).
Putting that together listily:
-
$data{$formname} => reference to an array
- dereference with @{ REFERENCE }
- $data{$formname}->[0] => the first element of that array. Perl lets you tighten that up to
$data{$formname}[0]. The element of that array is a reference to a hash, so
- dereference with %{ REFERENCE }
- $data{$formname}->[0]->{type} (also $data{$formname}[0]{type} ) => The value of the 'type' field in the anonymous hash. This is a normal scalar, and so needs no dereferencing.
So, to iterate over the keys of that (anonymous) hash, you might do
foreach my $key ( keys %{ $data{$formname}[0] } ) {
print $key, " ", $data{$formname}[0]{$key}, "\n";
}
HTH
If not P, what? Q maybe? "Sidney Morgenbesser" | [reply] [d/l] [select] |
Thank-you. That little tutorial was very useful. Thanks also to everyone who replied.
| [reply] |
The Data::Dumper module and its ilk in the Data:: namespace on CPAN might be useful also.
| [reply] |
foreach my $i (0 .. $#{ $data{$formname} }) {
print "$_: $data{$formname}->[$i]->{$_}\n"
foreach keys %{ $data{$formname}->[$i] };
}
See. perlreftut for more info.
HTH
_________ broquaint | [reply] [d/l] |
What you have here is a hash (indexed by form name), containing arrays of hashes. You can loop on the main hash, pulling out the specified fields from each hash in the array. For example:
while (my ($formname, $formarray) = each %data) {
print $formname, "\n";
foreach (@$formarray) {
print " type: ", $_->{type}, "\n";
print " field_name: ", $_->{field_name}, "\n";
print " value: ", $_->{value}, "\n";
}
}
Note: as broquaint mentioned, you should see perlreftut. I also find perldsc quite helpful at times. | [reply] |