Hi fellow monks
I am struggling with a small problem - I want to print the text following a match from a regular expression, until a match of a different regular expression.
The input is this: CR *FDA, 1997, GUID IND EXT REL OR
BADAWY SIF, 1996, INT J PHARM, V128, P45
(more lines w. similar formatting)
NR 42
Text with similar formatting is repeated many times in the input - I'd like to print everything between "CR " and "NR" - in all occurences in the file.
The code I have thus far is this:
use strict;
use warnings;
my @infile = (<>);
my ($citedreferences, $line);
my $n = 0;
foreach $line (@infile){
if ($line =~ m{^CR .+}gsi){
do{
$n++;
print $n . $line;
next;
}
until ($line =~ m{^NR}gsi)
}
};
However, this only prints the lines matching the first regular expression.
Any tips to point me in the right direction would be much appreaciated
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|