Don't ask to ask, just ask | |
PerlMonks |
Re: regular expression - grabbing everything problemby davido (Cardinal) |
on Aug 09, 2011 at 00:16 UTC ( [id://919355]=note: print w/replies, xml ) | Need Help?? |
If you wish to process the file line by line, you can use the flip-flop operator. This would make it unnecessary to use explicit control flags. Here's an example:
Updated as suggested in a followup to this post, by using eof as the RHS of the flip-flop. Nice if the script is altered to read from <>, as per the suggestion in a followup to this post. It seems strange to use Flip flop if you're only concerned with the initial flip. But it does work nicely. And if you're processing more than one file it can be used to catch the end of file to reset the search for the next file. The flip flop operator is discussed in the "Range Operators" section of perlop, as it's the same '..' operator. If you prefer to slurp the file into a string and process accordingly, you can do it like this:
Or even...
The split method could be altered to avoid capturing by using a lookahead assertion as the split point, like this:
This method creates only two elements; the one we don't want, and the one we do. The other split method created three elements; the one we don't want, the trigger text, and the rest of what we want to keep, so for that we have to specify that we want both elements 1 and 2. One liner versions of each of the above:
Dave
In Section
Seekers of Perl Wisdom
|
|