Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

uninitialized vs. undefined vs. !true and warnings. (code)

by deprecated (Priest)
on Jul 27, 2001 at 01:50 UTC ( [id://100164]=perlquestion: print w/replies, xml ) Need Help??

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

foreach my $stat (readdir ISSUE) { next if $stat =~ m/^0\./; # ignore 0.tiff et cetera next if $stat =~ m/^\.\.?/; # ignore current and parent direct +ory next unless defined $stat; warn "$stat\n" if $debug; if ($stat =~ m/tiffcheck/) { # line 50 open TIFF, "$logdir/$issue/$stat" or die "could not open $logdir/$issue/$stat: $!\n"; foreach my $line (<TIFF>) { next if $line =~ m/Starting/; next unless defined $line; if (($line =~ m/Completed/) and !$tiffcheck) { $tiffcheck = (split / /, $line)[2]; } else { $tiffcheck = "E"; } } close TIFF or warn "error closing $logdir/$issue/$stat: $!\n +"; }
produces this warning:
Use of uninitialized value in pattern match (m//) at summarizePg.pl li +ne 50.
This code has been removed from its context, so please ignore missing curlies and stuff. I provided the additional code for an idea of what is being done here. What has baffled me here <!- i dont want to hear it, tilly... -> is that i feel like I have taken every precaution against undefined and uninitialized values in this snippet -- and yet the m// is finding it uninitialized? How can this be? Is there a difference between "uninitialized" and "undefined" and perhaps "false" (i.e., 0 or "0")?

I am completely at a loss as to what is wrong here.

Thanks,
brother dep.

update:

tye and MeowChow were right. I was missing a ~ about 70 lines later in my code at an elsif. Damn difficult bug to track down!

--
Laziness, Impatience, Hubris, and Generosity.

Replies are listed 'Best First'.
(MeowChow) Re: uninitialized vs. undefined vs. !true and warnings.
by MeowChow (Vicar) on Jul 27, 2001 at 02:17 UTC
    In a list context, readdir is incapable of generating an undefined value, so you needn't bother with a defined test at all. I just had to point that out as part of my civic duty to eliminate unnecessary lines of code. As tye rightly suggested in the CB, your warning is in all likelyhood coming from elsewhere:
      
    #!/usr/bin/perl -w my $x; undef $x; if (0) { # LINE 5 print 'huh?'; } elsif ($x == 0) { print 'hmmm'; } ## output ## Use of uninitialized value in numeric eq (==) at - line 5. hmmm
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found