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.) > Is there a way to make perl do more of the detective work right from > the start? The warning about using undef only happens when you use undef as if it were a defined value; but by the time the value is being used, perl has lost track of what variable (or function) supplied the undef in the first place. Nobody has gone to the trouble, yet, to make a perl binary that traces undef back to its source. A patch to do so would be welcomed. Still, all you need to solve your problem is likely to be a few lines like this just before line 48 or so: warn "\$foo is undef" unless defined $foo; warn "\$bar is undef" unless defined $bar; Some person with an excess of cleverness and time on their hands could probably whip up a hack using a source filter to do just this. If they're clever enough not to cause spurious warnings for legitimate uses of undef, and maybe even if they aren't, it will become a popular module around these parts. Extra points if they properly handle functions that return undef. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/