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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.