In article <[EMAIL PROTECTED]>, Jenda Krynicky wrote:
> From: [EMAIL PROTECTED]
>> What I am trying to do is to take lines out of a file that are
>> formatted like:
>>
>> SYSTEM="value1" DOMAIN="value2" etc.
>>
>> There are about 1000 lines like that and what I need to do is to take
>> all of the keys (like system and domain) and put them into a hash. But
>> each of those keys has multiple values that it can have. I need to
>> then stick the values that each one has throughout the file into an
>> array, and put the array into the hash. It will be like this:
>>
>>
>> KEYS VALUES
>> system [value1, value2, value3...]
>> domain [value1, value2, value3...]
>>
>> I then need to print them out. How would I go about doing this?
>
> Assuming the variable names are words and the values are always
> quoted and do not span several lines you could do something like
> this:
>
> while (<FILE>) {
> while (/(\w+)="([^"]*)"/g) {
> push @{$data{$1}}, $2;
> }
> }
Here is my attempt...
my %sys;
while (<DATA>) {
my (undef, $system, undef, $domain) = split /"/, $_;
push @{$sys{$system}}, $domain;
}
I split on the quote mark (so they had better be there). I'm pretty sure
there is a way to use an array slice to pull just the 2nd and 4th value,
but I can't remember the syntax and so settled for the "(undef, $keep_this,
undef, etc...)" trick.
-K
--
Kevin Pfeiffer
International University Bremen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]