Hi,
I was able to parse different data in the same loop...however, now I'd
like to extract data from two files, using two while loops after
opening each .txt file...then do arithmetic with the data I
extracted...all in the same script. The problem is that when I
reference a variable in the second while loop that I initialized in
the first while loop, the script doesn't recognize it. To be more
clear, there is a number value for $SLPdataSFO[6] that I extracted in
the first while loop, and I'd like to subtract that value from
$SLPdataSAC[6], which I extracted in the second while loop. I tried to
make it a global variable at the beginning by using "our @SLPdataSFO =
();" to make it a global variable, but no luck there. Any ideas?
Thanks for your help....the error I receive is as follows with the
script after that.
Shad


Global symbol "@SLPdataSFO" requires explicit package name at c:\perl-
scripts\BarkerRegParser.cgi line 54.
Execution of c:\perl-scripts\BarkerRegParser.cgi aborted due to
compilation errors.


#!/perl/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Fcntl qw(:flock :seek);
use strict;

print header;
print start_html("Gradients");

open(FH, "C:/perl-scripts/Data/BarkerSFOtest.txt") #open barker SFO
extrapolated NAM data .txt file
or &dienice("couldn't open output file: $!");

print "<h2>PW</h2>";

while (my $line = <FH>) { #reads through each line of model data

if ($line =~ m/^ Mean/) { #finds line with sealevel pressure
print "$line<br>";
my $SFOdataSLP = $line; #places $line into new string called $data SLP
my @SLPdataSFO = split(/\s+/, $SFOdataSLP); #splits $data SLP string
into individual elements between whitespace
print "$SLPdataSFO[6]<br>";
print "$SLPdataSFO[4]<br>";
my $SLPchgSFO = $SLPdataSFO[6] -= $SLPdataSFO[4]; #subtracts 12hr SLP
from 0hr SLP
print "$SLPchgSFO<br>";
my $roundf = sprintf("%1.1f", $SLPchgSFO);
print "$roundf<br>";
}

elsif ($line =~ m/^ Precip/) { #if line isn't Precip Water line, then
will skip to next line
print "$line<br>";
my $dataPW = $line;
my @PWdata = split(/\s+/, $dataPW);
print "$PWdata[6]<br>";
}
}
close (FH);

open(FH, "C:/perl-scripts/Data/BarkerSACtest.txt") #open barker SFO
extrapolated NAM data .txt file
or &dienice("couldn't open output file: $!");

while (my $line = <FH>) { #reads through each line of model data

if ($line =~ m/^ Mean/) { #finds line with mean sealevel pressure
print "$line<br>";
my $SACdataSLP = $line; #places $line into new string called
$SACdataSLP
my @SLPdataSAC = split(/\s+/, $SACdataSLP); #splits $SACdataSLP string
into individual elements between whitespace
my $SACSFOgrad12 = $SLPdataSFO[6] -= $SLPdataSAC[6]; #subtracts SFO
from SAC 12-hr fcst sealevel pressure
print "$SACSFOgrad12";
}
}

close (FH);
print end_html;

sub dienice {
my($errmsg) = @_;
print "<h2>Error</h2>\n";
print "<p>$errmsg</p>\n";
print end_html;
exit;
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to