develooper Front page | perl.perl5.porters | Postings from January 2001

Re: [ID 20010112.006] perl misreports error location

From:
Joe Smith
Date:
January 27, 2001 19:02
Subject:
Re: [ID 20010112.006] perl misreports error location
Message ID:
3A738BA0.D0159BBD@inwap.com
The following test shows two things:
1) Use of an undefined value in an elsif reports the line number of the if().
2) When the body of an if(){} or elsif(){} block consists of a single
statement,
   the line number reported is that of the if().  These are marked with "!!".

Question: Should the first statement inside an if block always get its own
line number?  It seems inconsistent to do it only for multistatement blocks.

unix% cat -n temp
     1  #!/usr/bin/perl -w
     2  if ($ar[0] == 0) {
     3    print $ar[0] . "Single statement inside if(), on line 3!!\n";
     4  }
     5
     6  if ($ar[1] == 0) {
     7    $_++; print $ar[1] . "Multi statement inside if()\n";
     8  }
     9
    10  if ($ar[2] == 1) {
    11          # No statement here
    12  } else {
    13    print $ar[2] . "Single statement inside else\n";
    14  }
    15
    16  if ($ar[3] == 1) {
    17          # No statement here
    18  } else {
    19    $_++; print $ar[3] . "Multi statement inside else\n";
    20  }
    21
    22  if ($ar[4] == 1) {
    23    $_++;
    24  } elsif ($ar[5] == 0) {
    25    print $ar[5] . "Single statement inside elsif() on line 25!!\n";
    26  }
    27
    28  if ($ar[6] == 1) {
    29    $_++;
    30  } elsif ($ar[7] == 0) {
    31    $_++; print $ar[7] . "Multi statement inside elsif()\n";
    32  }
unix% perl temp
Use of uninitialized value in numeric eq (==) at temp line 2.
Use of uninitialized value in concatenation (.) or string at temp line 2.
Single statement inside if(), on line 3!!
Use of uninitialized value in numeric eq (==) at temp line 6.
Use of uninitialized value in concatenation (.) or string at temp line 7.
Multi statement inside if()
Use of uninitialized value in numeric eq (==) at temp line 10.
Use of uninitialized value in concatenation (.) or string at temp line 13.
Single statement inside else
Use of uninitialized value in numeric eq (==) at temp line 16.
Use of uninitialized value in concatenation (.) or string at temp line 19.
Multi statement inside else
Use of uninitialized value in numeric eq (==) at temp line 22.
Use of uninitialized value in numeric eq (==) at temp line 22.
Use of uninitialized value in concatenation (.) or string at temp line 22.
Single statement inside elsif() on line 25!!
Use of uninitialized value in numeric eq (==) at temp line 28.
Use of uninitialized value in numeric eq (==) at temp line 28.
Use of uninitialized value in concatenation (.) or string at temp line 31.
Multi statement inside elsif()

-- 
Joe.Smith@inwap.com    See http://www.inwap.com/ for details



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About