Jalcock501 has asked for the wisdom of the Perl Monks concerning the following question:
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:UPDATE: I forgot to add the type on data...#!/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 } }
Could someone help as I'm not sure if this is right.Q165HWN0X001 Q165HWN0X002 Q165HWN0X003 E99HEADER|006|001 E99INSSCH|052| E99POLCOM|1||IIL|62|35119849249024||||| E99INSFAC2|C00124||||||XAJX0727,YGAX0000,ZAAJ0203,VABA0018,WJZA1800| G35119849249024 h189SMA2
Thanks
Jim
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Reading file and matching lines
by choroba (Cardinal) on Feb 11, 2014 at 12:12 UTC | |
by robby_dobby (Hermit) on Feb 11, 2014 at 12:56 UTC | |
by Jalcock501 (Sexton) on Feb 11, 2014 at 13:26 UTC | |
by karlgoethebier (Abbot) on Feb 11, 2014 at 13:45 UTC | |
by GotToBTru (Prior) on Feb 11, 2014 at 14:23 UTC | |
Re: Reading file and matching lines
by Eily (Monsignor) on Feb 11, 2014 at 16:07 UTC | |
by tbone654 (Beadle) on Feb 11, 2014 at 20:26 UTC | |
by tbone654 (Beadle) on Feb 11, 2014 at 20:41 UTC | |
Re: Reading file and matching lines
by kcott (Archbishop) on Feb 12, 2014 at 08:34 UTC | |
by Jalcock501 (Sexton) on Feb 13, 2014 at 15:50 UTC | |
by kcott (Archbishop) on Feb 14, 2014 at 00:33 UTC |
Back to
Seekers of Perl Wisdom