Hi Joe!
I've been away dealing with other problems..its not that I am ignoring you! For example, the Tax man bites tomorrow and I had to deal with that! Ouch!
More to the Perl point: The use of the ... and .. pattern matching operators.
I've seen the ... op called the "flip-flop" operator. I don't know what these folks would call the .. operator. They are the same except that ... operates on multiple lines and .. operates on a single line.
Code examples are good so, here we go...!!
#!/usr/bin/perl -w
use strict;
while (<DATA>)
{
print if (/^TITLE:/.../^\s*$/);
}
__DATA__
TITLE:
qasfd
asfdikyh6rf76
khlyouyih
TITLE:
oiqywrot6
09809g808
asdfafTITLE:
stuff stuff that doesn't matter
[asDFKJKLAFG]
ASDFKJAFKLJ TITLE:
TITLE ASDFASFD
not a title paragraph
TITLE:
98797
ABCD
EFG
__END__
##### prints: #######
TITLE:
qasfd
asfdikyh6rf76
khlyouyih
TITLE:
oiqywrot6
09809g808
asdfafTITLE:
TITLE:
98797
ABCD
EFG
The above prints all lines between and inclusive of the lines that start with TITLE and have a blank line. The .. operator does about the same but is restricted to one line instead of multiple lines.
$1 has to do with first match in the "regex", Regular Expression.
Think of the ... op as kind of a filter. Once you are inside this "filtered" set of lines or tokens, then you can further filter things to further exclude what you don't want. This is like a funnel that takes in gallons and produces "shot glasses" of output.
Having said that, I'm not sure that this is the best way for what you are doing. I am actually not quite sure what your app is. If things haven't worked out, post some more info and we will talk about it.
|