Could you tell what you do inside the while loop? If you declare local
variables and assign values to them from the contents read from file, then
chances are that the values read from the file are null and the variables
still unassigned.

For example,

open( MYFILE, "file.txt" ) or die;
while ( my $line = <MYFILE> ) {
    my ($a);  // $a is undefined now.
    $line =~ /(\w+)\d+$/;  
    $a = $1;  // $a may be undef still if the preceding expression did not
evaluate to true
    print "Value of a is <$a>\n";  // Spits warnings!!
}
close <MYFILE>;

-----Original Message-----
From: Booher Timothy B 1stLt AFRL/MNAC
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002 2:39 PM
To: Hanson, Robert
Cc: [EMAIL PROTECTED]
Subject: RE: find blank line


Thanks so much - only one problem: when I try to use while (my $line =
<MYFILE>) { etc } I get a bunch of errors similar to this one:

Use of uninitialized value at JustForTest.pl line 13, <MYFILE> chunk 5.

Do you know what I am doing wrong?

Thanks,

tim

____________________________________________________
Timothy B Booher, Lt USAF, AFRL/MNAC
101 West Eglin Blvd, Suite 339 
Eglin AFB FL 32542-6810 
Phone: 850-882-8302 Ext. 3360 (DSN 872-)
FAX: 850-882-2201

 -----Original Message-----
From:   Hanson, Robert [mailto:[EMAIL PROTECTED]] 
Sent:   Wednesday, January 02, 2002 4:27 PM
To:     'Booher Timothy B 1stLt AFRL/MNAC'; [EMAIL PROTECTED]
Subject:        RE: find blank line


One way is to do this...

while ( my $line = <FILE> ) {
        next if ( /^\s*$/ );
}

Rob

-----Original Message-----
From: Booher Timothy B 1stLt AFRL/MNAC
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002 5:19 PM
To: [EMAIL PROTECTED]
Subject: find blank line


When parsing a text file - what is the best way to skip a "blank" line -
when I find the length I get a length of 1 (perhaps the newline). I know
that I could chomp($_) and then if(length($_) != 0) {do something} else
{next} but I feel that there should be a way to have an if($_ = $blank)
statement.

Any thoughts . . .

tim

____________________________________________________
Timothy B Booher, Lt USAF, AFRL/MNAC
101 West Eglin Blvd, Suite 339 
Eglin AFB FL 32542-6810 
Phone: 850-882-8302 Ext. 3360 (DSN 872-)
FAX: 850-882-2201

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to