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

Got it, sort of (Re: Array of hashes problem)

by chumley (Sexton)
on Apr 26, 2001 at 06:09 UTC ( [id://75693]=note: print w/replies, xml ) Need Help??


in reply to Getting information from an array of hashes

Data::Dumper showed me the way. What I had was not an "array of hashes". It was, as far as I can tell, an array containing one element, and that element was an array, containing the hashes.

I finally figured it out when I tried this on a hunch:

print "${${$diary_data[0]}[0]}{user}\n"; print "${${$diary_data[0]}[0]}{timestamp}\n"; print "${${$diary_data[0]}[0]}{value}\n";

which gave me some good output:

MAWEBB 988227105 NSA NOTIFY NETWORK MAINTENANCE 4/24/01 + 22:05 CST

From there, I was able to come up with:

$i=0; while (${${$diary_data[0]}[$i]}{user}) { print "User:\t\t${${$diary_data[0]}[$i]}{user}\n"; print "Timestamp:\t${${$diary_data[0]}[$i]}{timestamp}\n"; print "Information:\t${${$diary_data[0]}[$i]}{value}\n\n"; $i++; }

This gives me exactly the information I'm looking for. All that's left is munging it into a decent format for e-mail.

There are still some things I need to do with cleaning up this code, and I need to go back over exactly why this works the way it does, but I think I'm on the right track here. Thanks again Monks for the help today! :-)

Chumley

Replies are listed 'Best First'.
Re: Got it, sort of (Re: Array of hashes problem)
by hdp (Beadle) on Apr 26, 2001 at 06:47 UTC
    Glad to see you've figured out what this is.

    A little easier to write, and much easier to read, would be:

    for $hashref (@{$diary_data[0]}) { print "User:\t\t$hashref->{user}\n"; print "Timestamp:\t$hashref->{timestamp}\n"; print "Information:\t$hashref->{value}\n\n"; }
    If specifically testing for the user key is important, add a next unless $hashref->{user} or something.

    hdp.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found