Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: array of hashes, categorized by array index

by BrowserUk (Pope)
on Jun 26, 2013 at 21:32 UTC ( #1040848=note: print w/ replies, xml ) Need Help??


in reply to array of hashes, categorized by array index

Why "name" the fields. They are indexed numerically, so use the indexes to index your report array.

The following is a dump of @report. It shows that (from the 3 line sample supplied) field[0] contains 2x'483' and 1x'769'; field[1] contained 1 each of 3 values:'DS', 'OS', 'XO'; and so on.

C:\test\primes>..\junk83 [ { 483 => 2, 769 => 1 }, { DS => 1, OS => 1, XO => 1 }, { "dx-14" => 1, "dx-32" => 2 }, { 1 => 2, 5 => 1 }, { charles => 1, james => 1, sully => 1 }, { list3 => 1, list4 => 1, nolist => 1 }, { "23.456.12.7" => 1, "aardvark.com" => 1, "widgets.com" => 1 }, { "ty-off" => 1, "ty-on" => 2 }, { "lx-on" => 3 }, { B => 1, C => 1, V => 1 }, { "01" => 2, "07" => 1 }, ]

Code to produce the above output:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @report; while( <DATA> ) { my @f = split ' ', $_; for my $field ( 0 .. $#f ) { $report[ $field ]{ $f[ $field ] }++; } } pp \@report; __DATA__ 483 OS dx-32 1 charles list4 aardvark.com ty-off lx-on C 01 483 DS dx-14 1 james list3 23.456.12.7 ty-on lx-on B 01 769 XO dx-32 5 sully nolist widgets.com ty-on lx-on V 07

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: array of hashes, categorized by array index
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-07-10 04:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (199 votes), past polls