Why does perl report an invalid line number for this warning regarding the uninitialized value used in elsif?

I get a strange warning from some Perl code, and I hope the SO brain can help.

This code:

sub add_observation {
    my $self = shift;
    my $observation = shift;

    my $result = $observation->get_datum_result($self->{datum_name});
    if(!(defined $result)) {
        croak("Datum '$self->{datum_name}' not defined for this observation: ". Dumper($observation));
    }
    $self->{result} |= $result;
    my $observation_time = $observation->get_time();

    if($self->{result} == 0){
        $self->set_start_time($observation_time);
    }
    if($result != 0) {
        $self->set_end_time($observation_time);
        $self->{end_threshold} = $observation_time->epoch() + $self->{timeout};
    }
    elsif($observation_time->epoch() > $self->{end_threshold}) {
        $self->{complete} = 1;
    }

    return $self->{result}; 
}

When I run my code, I get the following warning:

Use of uninitialized value in numeric gt (>) at Performance/BadSpan.pm line 67 (#1)

Line 67 corresponds to line if($result != 0) {.

My problem is twofold:

  • Why $resultdoes Perl claim to be undefined when it has security code in front of it that ensures it is defined
  • Perl gt, gt . , , , Perl , , , != "" > <?
+5
3

perl?

use strict; use warnings;

my $x;

if ( $x ) {
    print "here\n";
}
elsif ( $x > 1 ) {
    print "there\n";
}

perl 5.10.1 :

Use of uninitialized value $x in numeric gt (>) at C:\Temp\t.pl line 8.

, elsif , if, , , if.

perltodo :

  1. use warnings;
  2. my $undef;
  3.
  4. if ($undef == 3) {
  5. } elsif ($undef == 0) {
  6. }

:

  Use of uninitialized value in numeric eq (==) at wrong.pl line 4.
  Use of uninitialized value in numeric eq (==) at wrong.pl line 4.

- ​​ 5. - - , if elsif OP, , PL_curcop - 4. , OPs elsif, , nextstate OP OP, live nextstate OP, . (Jenga!)

, elsif ( elsif ).

   1. use warnings;
   2. my $undef;
   3.
   4. my $a = $undef + 1;
   5. my $b
   6. = $undef
   7. + 1;

   Use of uninitialized value $undef in addition (+) at wrong.pl line 4.
   Use of uninitialized value $undef in addition (+) at wrong.pl line 7.

( 4 5), , -, , OP ( ) .

, BASEOP op, , . . ( repack the optree), ops . , OP . , op nextstate-light ( PL_curcop), , , op. , . ( , repack optpect, / OP)

( , , , )

commit. , 2008 , , 5.8.9 (. perlhist).

+8

gt (>)
elsif($observation_time->epoch() > $self->{end_threshold}) {

elsif, if 67. , . $observation_time->epoch() $self->{end_threshold} undefined?

+2

This is probably >in the sentence elsif. Check these values.

0
source

All Articles