Thanks again. After processing more records I hit another issue. I thoght single empty line is record separator. But i notice that the comment line includes some empty lines as well.
(Please read my original posting for clearer understanding what I am looking at) Is there anyway to define in perl that the line starts host= is the record beginning and env=<somevalue> is the record end?? host=host1 network=10.x.x.x ip=10.x.x.x gw=10.x.x.1 history=history1 some comments.. multi line with some indentation at the beginning) loc=loc1 owner=owner1 env=env1 host=host2 network=10.x.x.x ip=10.x.x.1 gw=10.x.x.1 history=history2 some comments (multi line comments some indetation at the begining) owner=owner2 env=env2 I thought of opening new thread but it is more related to the same issue that i am dealing with tx > 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/