Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
On Fri, 4 May 2007, McNutt, Justin M. wrote:
The way you would do this in Perl is to set the line separator to
"undef" and then include the newlines in your pattern, like this:
undef $/; # "slurp mode"
if ( $input =~
/pattern[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n[^\n]*\n
[^\n]*\n([^\n]*)\n/ ) {
$ninthline = $1;
}
Basically, match your pattern, then match nine newlines in a row,
regardless of what is between the newlines, and grab what's between the
ninth and tenth newlines.
So that wouldn't mess up in the way that egrep messes up. I was thinking
along those lines too but didn't know some of those tricks. Here's one
for you: To repeat something n times, use {n}, where "n" is some integer:
if ( $input =~
/pattern[^\n]*\n{9}([^\n]*)\n/ ) {
$ninthline = $1;
}
So I think that is equivalent to the above. That makes it a lot easier to
change the number of lines as needed or to deal with skipping large
numbers of lines.
Mike
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members