On 6/27/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I would suggest splitting each record on "\n", looping
> over the results checking to see if the first character is a space,
> and appending that line to the last field if it is or creating a new
> key/value pair if it isn't.

thank you. Would you mind posting sample code that does this trick?

There is nothing tricky about it. (warning untested code)

my @records;
local $/ = "\n\n"; #records are separated by two line feeds
while (<>) {
   my %rec;
   my $name;
   for my $field (split /\n/) {
       if ($field =~ /^ /) { #or if (substr($field,0, 1) eq ' ') { your choice
           $rec{$name} .= $field;
           next;
       }
       ($name, my $value) = split /=/, $field;
       $rec{$name} = $value;
   }
   push @records, \%rec;
}

for my $rec (@records) {
   print "$rec->{host} is owned by $rec->{owner}\n";
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to