Agreement.
The key point is that you can't read part of the data,
do the match, and then expect to be able to read all of
the data.
Instead, read each record, see if it matches, then
print it.
If paragraph mode doesn't work (i.e. not always a blank
line between records), you can do it manually with
something like:
sub readrec
{
my $line;
my $inrec;
my $rec;
while (defined($line = <FH>)) {
last if $line eq "</ref>\n";
$rec .= $line if $inrec;
$inrec ||= $line eq "<ref>\n";
}
$rec;
}
(This actually strips off the <ref> and </ref> tags; if
you want to preserve them, reverse the order of the lines
in the while loop.)
You could also parse the record as you read it, but to
search any of the fields, its probably more convenient
to return just a string to match against, and split it
up into the components if it matches.
(BTW, the OP's match statement doesn't look
as if it would work at all.)
(updated to remove comment about match based on misunderstanding)
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.