Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Categorization Problem

by injunjoel (Priest)
on Nov 02, 2005 at 22:32 UTC ( #505152=note: print w/replies, xml ) Need Help??

in reply to Categorization Problem

Well if I am reading your question right I would suggest using a hash for the locations array you mentioned. That way the location is a unique key in the hash and can thus be found a lot easier than grepping through an array. Now the user information. I would store that in a "users" key in the location hash, either a hash of login as the key to names or an array. This would allow for you to add more categorical information to the location structure, maybe ip address, or something similar.
so conceptually I would think something like this
%locations = ( "location1" => { "users" => { "Login1" => "Name1", "Login2" => "Name2", ... ], "ip" => "", "otherinfo" => [ "info", "info2","infoblah"...] }, "location2" => { "users" => { "Login1" => "Name1", "Login2" => "Name2", ... ], "ip" => "", "otherinfo" => [ "info", "info2","infoblah"...] }, ... )

In order to do that you can take advantage of autovivification with regard to datastructures.
Here is a start.
use strict; #input format for testing my $string = 'fooLogin,barName,bazLocation,Info,Info2,Infoblah'; my %locations; #split it up on commas from our example. #you would need to decide what to do with the rest. my @temp_info = split /,/,$string; $locations{$temp_info[2]}->{users}->{$temp_info[0]} = $temp_info[1]; $locations{$temp_info[2]}->{otherinfo} = [@temp_info[3..$#temp_info]];
First off though I would read perldsc and perlref. Oh and you will want to use Dumpvalue or Data::Dumper to check your work.
Good luck and I hope that helped.
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2019-07-24 08:37 GMT
Find Nodes?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?

    Results (32 votes). Check out past polls.