in reply to how to hash this

You've got lots of problems here. First off, while (<file>) doesn't do what you think it does. While will actually return the contents of a file line by line, where "line" is defined by "some data that ends in a \n" (actually, it's "some data that ends with the contents of $/" where $/ defaults to \n). Anyway, as written your code will pull in one newline separated line at a time, not an entire "record" like it appears you want.

In this case you don't want to read the record line-by-line. You want to read it record-by-record, where each record is delineated by a "Begin Product/End Product" pair. This is what I'd do in a case like this: (untested code ahead)

open (FILE, $lfilename) or &dienice; $/ = undef; # Slurp mode $file = (<FILE>); # Grab the whole file into $file while ($file =~ m/Begin Product(.*?)End Product/gs) { my $record = $1; # Now $record contains the entire contents of exactly one # record from your file. You can now fold, spindle, and # otherwise mutilate $record to pull out the various # and sundry pieces for each record. }
As far as the folding, spindling, and mutilating goes you're on your own. Your file format is so irregular that you'll have to meticulously parse it bit by bit. Something like "split" only works on regular formatted records, which you don't have here. You may end up doing additional regex matches for "Begin Option/End Option" within each record. It ain't pretty; the more irregular your data is the uglier the code is going to be extracting it.

Gary Blackburn
Trained Killer

Update: Corrected a stupid error. This is why I shouldn't code this late at night. :-P

Replies are listed 'Best First'.
Re: Re: how to hash this
by malaga (Pilgrim) on Mar 31, 2001 at 09:47 UTC
    ok! that gives me something to work with. thanks for your help. i've been working on this all day (pathetic) and wasn't getting anywhere. thanks trimbach.
Re: Re: how to hash this
by malaga (Pilgrim) on Mar 31, 2001 at 09:11 UTC
    i'm trying - nothing prints. i've been working on this all day, and it's always the same - i either get all the data in the whole file, or nothing. it never see's just one record.
    open(FILE, "$lfilename") or &dienice; $/ = undef; # Slurp mode $file = (<FILE>); # Grab the whole file into $file while (my($record) =~ m/Begin Product(.*?)End Product/gs) { print $record; }