Smitty has asked for the wisdom of the Perl Monks concerning the following question:
I capture a series of fields, as an example:
and then use an auto-vivifying hash to act as a counter of the unique data set:my($ip,$name,$proto,$email) =~ /^(\S*) (\S*) (\S*) (\S*)$/;
Clearly this allows tracking the number of times a given NAME was used, along with the various IPs, and for each of those PROTOs, and finally EMAILs.$userdata{$name}{$ip}{$proto}{$email}++;
But this has a built-in order. I'd like to be able to allow a user-configurable ordering of that data, for example:
such that I could capture essentially as:@order = qw(ip name email proto)
essentially changing the primary, secondary, etc. key orders. Creating the many combinatorics to suit all cases isn't an option of course.$userdata{$order[0]}{$order[1]}{$order[2]}{$[order[3]}++; # which I want to result in ... $userdata{$ip}{$name}{$email}{$proto}++;
Can anyone suggest a mechanism to accomplish this that is a) fast, and b) not terribly memory intensive. The amount of data can be quite large, and is coming from a plain text file and not a DB.
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Configurable key orders
by Fletch (Bishop) on Jun 22, 2008 at 16:41 UTC | |
|
Re: Configurable key orders
by samtregar (Abbot) on Jun 22, 2008 at 17:55 UTC | |
|
Re: Configurable key orders
by roboticus (Chancellor) on Jun 22, 2008 at 17:10 UTC |