Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Accessing this array ref.

by SuicideJunkie (Vicar)
on Apr 03, 2013 at 18:41 UTC ( [id://1026888]=note: print w/replies, xml ) Need Help??


in reply to Accessing this array ref.

You have an array reference. Each element of the array is a hash reference.

So, when you loop, you are doing:

for my $hashRef ( @$my_array_ref ) # Curlies aren't needed here since +$my_array_ref is a simple variable name { ... }

For each hash ref, you can inspect the contents via: $hashRef->{name} or $hashRef->{type} etc...

It looks like you want to spin through all the data and build a new Hash of Hashes (HoH):

$results->{$transactionType}{$purchasedThing} += $amountSpent
or some such like that.

When looping through the hashes to display, you probably want to sort the keys so that you print in the same order each time.

for my $transactionType (sort keys %$results) { for my $purchasedThings (sort keys %{ $results->{$transactionType} } +) # Curlies here to mark out what to dereference { printf("spent \$%5d on %20s using %20s\n", $results->{$transactionType}{$purchasedThings}, $purchasedThings, $transactionType, ); } }

Replies are listed 'Best First'.
Re^2: Accessing this array ref.
by Anonymous Monk on Apr 03, 2013 at 18:57 UTC
    your explanation makes sense, still having problems, I can print the first item from the array like this:
    print $results->[0];
    But running your code is giving me": Not a HASH reference".

      It sounds like you're defining $results somewhere that you haven't shown, and making it an array ref.

      As I understand it, you want results to be a hash of hashes, so just declare it as my $results; or my $results = {};

Log In?
Username:
Password:

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

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

    No recent polls found