Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

by deprecated (Priest)
on Jul 27, 2001 at 01:50 UTC ( #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 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.

brother dep.


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
                   s aamecha.s a..a\u$&owag.print

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2023-06-06 10:25 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (26 votes). Check out past polls.