Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Trying to skip for $LEV = 0

by MKevin (Novice)
on Jan 28, 2007 at 06:16 UTC ( [id://596942]=perlquestion: print w/replies, xml ) Need Help??

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. # # @project Kat # @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 ' '; next DATA if ($LEV =~ /0/); 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);
Now how do i make the program skip to the next line and conduct the rest of itself when $LEV = 0

Replies are listed 'Best First'.
Re: Trying to skip for $LEV = 0
by dorko (Prior) on Jan 28, 2007 at 07:01 UTC
    DATA is a file handle, but it looks like your trying to use it as a label.

    Also, I'm not sure why your trying to use a matching regular expression. I'd test for equality. Instead of:
    next DATA if ($LEV =~ /0/);

    try:
    next if ($LEV == 0);  # $LEV is a number -- NO DATA
    or
    next if ($LEV eq '0')  # $LEV is a string -- NO DATA

    Without examples of your data, these suggestions are just guesses.

    Cheers,

    Brent

    -- Yeah, I'm a Delt.
Re: Trying to skip for $LEV = 0
by virtualsue (Vicar) on Jan 28, 2007 at 11:28 UTC
    Beware of using regular expressions in place of '==':
    #!/usr/bin/perl use warnings; use strict; my $val = 1100; print "Value contains a 0\n" if $val =~ /0/; print "Value is actually equal to 0\n" if $val =~ /^0$/;
    Don't obfuscate your code by using pattern matching when you don't need it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://596942]
Approved by ysth
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-24 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found