martialartsdrum
Programmer
- Oct 21, 2011
- 1
Hi All,
I am a relative newbie to perl and running into a syntax issue.
I need to open a file, search for a certain flag, then extract and manipulate data until another flag is reached.
pseudo code:
open file
while not EOF
read line
if line contains search_flag
while line does not contain end_flag
manipulate data
What I am running into, is that the perl code loops in the while loop waiting for the end_flag and it is never reached because we are not reading from the file from within the loop.
$file = $ARGV[0]; # Name the file
open(INPUTFILE, $file) || die "couldn't open the file!";
@lines = <INPUTFILE>;
foreach (@lines)
{
my($line) = $_;
chomp($line);
if ($line =~ /Processing table/)
{
while ($line !~ /99: VolumeTable/)
{
# here is where I need to manipulate the data
# and increment line.
}
}
}
SO.. the quesion is. How is this accomplished?
thanks
John
I am a relative newbie to perl and running into a syntax issue.
I need to open a file, search for a certain flag, then extract and manipulate data until another flag is reached.
pseudo code:
open file
while not EOF
read line
if line contains search_flag
while line does not contain end_flag
manipulate data
What I am running into, is that the perl code loops in the while loop waiting for the end_flag and it is never reached because we are not reading from the file from within the loop.
$file = $ARGV[0]; # Name the file
open(INPUTFILE, $file) || die "couldn't open the file!";
@lines = <INPUTFILE>;
foreach (@lines)
{
my($line) = $_;
chomp($line);
if ($line =~ /Processing table/)
{
while ($line !~ /99: VolumeTable/)
{
# here is where I need to manipulate the data
# and increment line.
}
}
}
SO.. the quesion is. How is this accomplished?
thanks
John