in reply to Re^5: Hash of Hashes from file
in thread Hash of Hashes from file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Hash of Hashes from file
by Cristoforo (Curate) on Apr 06, 2012 at 02:17 UTC | |
From this data: Notice that there are quotes surrounding every field. The regular expression that captures these fields from the file would need to be changed if thats not the case. In my program I use 2 hashes - one to count the number of sites visited by each user, %count, and one to count each address and category (by user), %data. It seems to work OK for this small data set. The line $data{$user}{ qq{$site$;$cat} }++; uses a 'compound' key ($site and $cat joined by $;). Here is a dump of %data.
Update: Whoops, that doesn't count the categories correctly :-( | [reply] [d/l] [select] |
by Cristoforo (Curate) on Apr 06, 2012 at 15:08 UTC | |
And here is the code: Hope this helps, Chris Update: Added sub by_count_desc. | [reply] [d/l] [select] |
by Cristoforo (Curate) on Apr 14, 2012 at 14:54 UTC | |
I thought I'd post a database solution. Its not really necessary as the Perl code solution works. The advantage of loading into a database is if your file is too large to fit in memory. Also, if you wanted to see different views of the data, it would be probably easier to write an SQL query than to write another program, etc. I can't vouch for the SQL here - I don't use it often, but it did produce the results similiar to the Perl program above. You could run it if you had the DBI and DBD::SQLite modules on your system. The first program creates the database and the second program runs the queries.
Chris Update: Re-wrote the query in loop of '@users'. | [reply] [d/l] [select] |
by cipher (Acolyte) on Apr 09, 2012 at 12:04 UTC | |
| [reply] |