in reply to Re: Usage of regular expressions in input separator
in thread Usage of regular expressions in input separator
It would be slick if we could:$/ = sub { my ($line) = @_; $line =~ m{Separator\s+\d+}; };
Yes, but the whole point of $/ is to make lines or records from the bits in a file. So there is no "line" before $/ ...
You could feed the code ref with chunks of a file, but even that would not be sufficient. Imagine a file with a two-byte record separator (e.g. that old CR-LF from DOS). The first chunk ends with the first byte of the record separator (i.e. CR), the second chunk begins with the second byte of the record separator (i.e. LF). Unless you manage to maintain some state information, you would not be able to detect the record separator.
That state information has to be per file handle, or else you mix data from different files. So you can not use global or state variables, unless you also pass the handle to the code ref and use it to index arrays or hashes with status data.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Usage of regular expressions in input separator
by jdrago999 (Pilgrim) on Jan 04, 2012 at 23:39 UTC |