Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: use warnings => Use of uninitialized value...

by jeanluca (Deacon)
on May 24, 2006 at 10:14 UTC ( [id://551321]=note: print w/replies, xml ) Need Help??


in reply to use warnings => Use of uninitialized value...

Here is a good one. When I run my program I get the following warnings:
test 1 || Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.7/myTool.pm line 316. test 1 || Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.7/myTool.pm line 316.
Here is the code
read $fh, $binrec, $l ; print "test 1 |$binrec|\n" ; if ( $binrec ) { # this is line 316 print "test 2\n" ; ... }
So, how come that there is a problem with this line ??

luca

Replies are listed 'Best First'.
Re^2: use warnings => Use of uninitialized value...
by roboticus (Chancellor) on May 24, 2006 at 11:57 UTC
    jeanluca:

    The problem is that you're using $binrec before you know if it's defined. It appears that the error occurs in your print or if statement.

    After reading read, I don't see anything that indicates that SCALAR is changed if nothing can be read due to an error. In that case, SCALAR may still be undefined. In that event, you can change the code to:

    read $fh, $binrec, $1; if (defined $binrec) { print "test 1 |$binrec|\n"; . . . } else { print 'test 2: undefined $binrec!\n'; }
    --roboticus
Re^2: use warnings => Use of uninitialized value...
by rhesa (Vicar) on May 24, 2006 at 11:00 UTC
    The actual problem is likely in an elsif() condition. Those are lumped together at the if() line:
    use strict; use warnings; my $foo; my $bar = 1; if( $bar - 1 ) { # line 7 print $bar; } elsif( $foo - 1 ) { # throws warning -- at line 7! print "$foo\n"; my $baz = 2 * $foo; } __END__ Use of uninitialized value in subtraction (-) at - line 7. Use of uninitialized value in concatenation (.) or string at - line 10 +. Use of uninitialized value in multiplication (*) at - line 11.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found