This is clearly not your actual code, not only because of the syntax error in your regexes that tilly pointed out, but also because, if it were your actual code (and the syntax error were fixed), then the second snippet would work.
#!perl
undef $/;
$text = <DATA>;
while ($text =~/foo(.*?)bar/g) {
manipulate ($1)
}
sub manipulate {
print "@_\n";
}
__DATA__
foo this is one example bar
this is a line I don't care about
foo here's another keeper! bar
foo yet another bar
and a line to reject
and the output:
this is one example
here's another keeper!
yet another
Please provide some code, whether it's your original code or a short snippet, that actually demonstrates the problem you are having.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.