Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Categorization Problem

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


in reply to Categorization Problem

Greetings,
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" => "127.0.0.1", "otherinfo" => [ "info", "info2","infoblah"...] }, "location2" => { "users" => { "Login1" => "Name1", "Login2" => "Name2", ... ], "ip" => "127.0.0.1", "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.
-InjunJoel
"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?
Username:
Password:

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

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

    No recent polls found