Good Afternoon my fellow monks!
I am need of your assistance, I need to look through a file and read it line by line. And this is the tricky bit (for me at least). Whilst reading the first character on line A which should begin with an E and then search through the lines until I find a line beginning with G.
But if we hit a line beginning with h<lower case> we've gone to far and the script should produce an error. Now I though maybe using a FOR loop to loop through the lines one at a time however I've never done this in perl so here was my crack at it:
#!/usr/bin/perl
use strict;
my @lines;
my $file = <quoteout.dat>;
open my $in, '<', $file;
open my $out, '>', "ERR";
@lines = split('', $_);
for(my $i; $i < 9; $i++)
{
if($line[$i] eq 'E')
{
#add one until finds a G or h
}
}
UPDATE: I forgot to add the type on data...
Q165HWN0X001
Q165HWN0X002
Q165HWN0X003
E99HEADER|006|001
E99INSSCH|052|
E99POLCOM|1||IIL|62|35119849249024|||||
E99INSFAC2|C00124||||||XAJX0727,YGAX0000,ZAAJ0203,VABA0018,WJZA1800|
G35119849249024
h189SMA2
Could someone help as I'm not sure if this is right.
Thanks
Jim
-
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.