Matt Simonsen wrote at Tue, 01 Oct 2002 01:00:41 +0200:

> I need to get 2 fields out of a file which has the following format:
> 
> 
> #FIELD
> [tab]NAME=name to put into hash[newline]
> [tab]DATALINE=value to put with data[newline]
> [tab]EXTRA=several fields to ignore...
                                        ^^^^^^
I assume, there is also a [newline].

> [NEWLINE]
> #NEXTFIELD
> [tab]NAME ...
> 
> 
> I have thought of a couple ways I *could* do it, but I think they are
> the poorer of the many ways to do it.
> 
> Any tips on how you'd elegantly separate the data would be appreciated.

What is the exact data you want to separate.
What have you tried already ?
Why do you think your ways are poor ?

It's hard for us to give you good hints without enough information.

I assume you want to read field for field,
and fill e.g. a hash with the name,dataline,...and so on
 
local $/ = "\n\n";  # Now a line is everything till an empty line
while (<DATA>) {
   my $field = /^#(.*)$/;
   my %info  = /^\t(.*?)=(.*)$/gm;

   # Now $info{NAME} should hold the name,
   #     $info{DATALINE} the dataline and so on
}

[untested]


Best Wishes,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to