Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: How to access info from the array

by arturo (Vicar)
on Nov 12, 2002 at 21:20 UTC ( #212416=note: print w/replies, xml ) Need Help??

in reply to How to access info from the array

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"; }


If not P, what? Q maybe?
"Sidney Morgenbesser"

Replies are listed 'Best First'.
Re: Re: How to access info from the array
by gnangia (Scribe) on Nov 12, 2002 at 21:33 UTC
    Thank-you. That little tutorial was very useful.
    Thanks also to everyone who replied.
      The Data::Dumper module and its ilk in the Data:: namespace on CPAN might be useful also.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://212416]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2023-05-31 11:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found