G'day dhannotte,
"1) Why isn't Carp identifying the correct line?"
Perl will do its best to parse whatever code you provide.
When it decides it definitely can't continue, it provides the line number where it gave up.
It could be the problem line;
it could be within the next few lines;
it could be many pages of code later.
Whilst it obviously depends on the code in question,
the second case is probably the most common;
the first case is less common;
and, for the third case, you'll often get some sort of hint
(e.g. Might be a runaway multi-line %s string starting on line %d).
So, for your posted problem, look at the lines just before 2842
for code like "defined @some_array_name".
"2) Besides going through 101 occurences, how can I find where (and WHAT) this error really is? "
You can look in perldiag for diagnostic messages.
Here you'll find the
error message you posted
along with a description of the problem.
You've shown "testplx.pl in its entirety".
That code is missing these two lines (which should be at the top):
use strict;
use warnings;
[See strict
and warnings for details.]
As a developer tool (i.e. don't include this in production code),
you can also use the diagnostics pragma:
this will give you the full description associated with the diagnostic message.
I suspect your other code is also missing one, or both, of those lines.
Plx.pm certainly doesn't have warnings:
if it did, you would have received deprecation warnings (not errors)
and could have fixed them as they occurred.
Presumably, after receiving the first few, you would have stopped making that mistake.
Rather than looking at every instance of defined in your code,
many of which may be perfectly fine (e.g. defined $some_scalar),
it might be easier to keep running your script and fixing each as they occur.
Bear in mind that these are fatal errors;
each will be reported separately, even if they occur on the same line:
$ perl -E 'my (@x, @y); say defined(@x) ? 1 : 0; say defined(@y) ? 1 :
+ 0'
Can't use 'defined(@array)' (Maybe you should just omit the defined()?
+) at -e line 1.
$ perl -E 'my (@x, @y); say @x ? 1 : 0; say defined(@y) ? 1 : 0'
Can't use 'defined(@array)' (Maybe you should just omit the defined()?
+) at -e line 1.
$ perl -E 'my (@x, @y); say @x ? 1 : 0; say @y ? 1 : 0'
0
0
|