In the name of Tim Toady (There Is More Than One Way To Do It). Featuring the range, or flip-flop operator, which translates in human as "From .. till ..", and the next keyword.
my $count =0;
LINE: while(<DATA>)
{
next LINE unless /^E/../^G/; # next line unless we are between a li
+ne starting with a end a line starting with G
die "Oups, went too far!" if /^h/; # error if the line starts with
+an h and hasn't been skipped by the previous statment
$count++ unless /^G/; # count that do not start with a G
}
__DATA__
Q165HWN0X001
Q165HWN0X002
Q165HWN0X003
E99HEADER|006|001
E99INSSCH|052|
E99POLCOM|1||IIL|62|35119849249024|||||
E99INSFAC2|C00124||||||XAJX0727,YGAX0000,ZAAJ0203,VABA0018,WJZA1800|
G35119849249024
h189SMA2
-
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.
|