Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to access info from the array

by arturo (Vicar)
on Nov 12, 2002 at 21:20 UTC ( [id://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"; }

HTH

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found