"Tom Phoenix" <[EMAIL PROTECTED]> writes:

> On 12/10/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>> Can the perl interpreter be made to give more exact warning about
>> undeclared variables?
>
> Not easily, alas.
>
>> I get this warning:
>>
>>    Use of uninitialized value in concatenation (.) \
>>    or string at ../keywa/kywpl line 49.
>>
>> But there is no code at that line... its a blank line.
>> The code immediately above has several vars in it but all appear to
>> have been given some value.
>
> Appearances are deceiving. Something, probably a variable, on one of
> the lines just before line 49 is giving undef instead of a defined
> value. (The line number is the one in which perl first realized the
> problem, so it should be near, but sometimes after, the true location
> of the problem. Modern versions of perl are pretty good about getting
> things right for code that's formatted in the usual way, but there
> will always be some exceptions.)

[ First thanks for the info ]

Two claused before line 49 look like:

   if ($ARGV[1]){
      $OutputFile  = pop @ARGV;
       if (! -f $OutputFile){
           usage();
           print "<$OutputFile> cannot be found .. exiting\n";
           exit;
        }
   }
   
   ## If no output file was given on cmdline we use a default
   if (!$OutputFile){
       $OutputFile  = "/home/reader/projects/perl/work/myfile";
       if(! -f $OutputFile){
          usage();
          print "<$OutputFile> cannot be found .. exiting\n";
          exit;
       }
   }
[line 49]

Seems like these two by thier nature would not report undef.  But I
probably don't know what I think I know about them.   

But I did stick an undef in at if (!$OutputFile) so
 if (undef $OutputFile)

Then the warning moved on to line 66 where the code attempts to use
OutputFile.  Seems to indicate OutputFile was gettiong a varlue in the
if clause.

[...]

>   warn "\$foo is undef" unless defined $foo;
>   warn "\$bar is undef" unless defined $bar;

Good tip for debugging .. thanks

> Some person with an excess of cleverness... 

Well that clearly rules me out.  hehe.

Put it looks like Paul has good news on that front.  I'm compiling
that version now... Just to see what it does say.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to