MKevin has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl -w # ## Copyright (c) 2007 # my $pkgdoc = <<'EOD'; #/**-------------------------------------------------- # @ file radiosondeparcer.pl # This scirpt parces the fetched radiosonde data from # the plymoth website. # # @ussage radiosondeparcer.pl ddd.hh.yyyy.index.txt # date: Jan 18, 2007 #---------------------------------------------------*/ EOD # $Log$ use strict; use warnings; use Getopt::Long; if (@ARGV <1) { print $pkgdoc; exit -1; } my $txtfile = shift; my $lat; my $long; open (DATA, $txtfile)||die "cannot open $txtfile for reading"; # First seek location line while (<DATA>) { next unless /(-?\d+(?:\.\d*)?)\s+ (-?\d+(?:\.\d*)?)\s+ \d+\s \d+/ +x; ($lat, $long) = ($1, $2); last; } # print "$lat, $long\n"; # Skip to data lines while (<DATA>) {last if /^-+$/}; while (<DATA>) {last if /^-+$/}; open (OUT, ">$txtfile.redo"); # Skip to data lines to get scf data while (<DATA>) { my ($LEV, $PRES, $HGHT, $TEMP, $DEWP, $RH, $DD, $WETB, $DIR, $SP +D, $THETA, $THEV, $THEW) = split ' '; if ($LEV && $LEV =~ /SFC/) { last unless defined $SPD; print OUT "$lat $long $PRES $HGHT $TEMP $DEWP $D +IR $SPD\n"; } if ($PRES && $PRES =~ /850|500|250/) { last unless defined $SPD; print OUT "$lat $long $PRES $HGHT $TEMP $DEWP $D +IR $SPD\n"; } last unless defined $THEW; } close (DATA); close (OUT);
I keep getting these error messages:
Use of uninitialized value in pattern match (m//) at ./radiosondeparce +r.pl line 59, <DATA> line 60. Use of uninitialized value in pattern match (m//) at ./radiosondeparce +r.pl line 63, <DATA> line 60.
can you help me correct these two errors PROBLEM SOLVED THANKS Don't forget its  $LEV && $LEV not  $LEV the first intiallizes the variable

Replies are listed 'Best First'.
Re: Errors on Parser help
by madbombX (Hermit) on Jan 25, 2007 at 12:30 UTC
    It would be helpful if you provided us with some sample data. But what this message means is that your regexp did not match something that you expected it to match. It's tough to help debug a regexp when we don't know what the sample data looks like.

    Also, you checked the return value of your first open (although you didn't explicitly specify weather you are opening it for read/write/both which is a good habit to be in):

    open (DATA, $txtfile)||die "cannot open $txtfile for reading";
    But you didn't check the return value of the second open:
    open (OUT, ">$txtfile.redo");
    You should rewrite both of your open's to use the 3 argument form and always check the return values:
    open(DATA, ">", $txtfile) or die "File open error: $!";
Re: Errors on Parser help
by TOD (Friar) on Jan 25, 2007 at 06:50 UTC
    take a look at the message in the perl debugger:
    #!/usr/bin/perl -wd