[Israel.pm] undefined subroutines not detected at compile time

Mikhael Goikhman migo at homemail.com
Thu Mar 17 08:54:34 PST 2005


On 17 Mar 2005 09:07:07 +0200, Yossi.Itzkovich at ecitele.com wrote:
> Mikhael Goikhman wrote:
> > On 15 Mar 2005 15:30:52 +0200, Yossi.Itzkovich at ecitele.com wrote:
> > >
> > > When I use both   -w and use strict, I expect Perl to find undefined
> > > subroutines at compile time (assuming I don't use references to
> > > subroutines).
> > 
> > This can't be checked at compile time. Here are 3 examples that
> > demonstrate why (all are perfectly valid perl idioms that are used
> > in real life, yet you suggest that they should issue a warning).
> > 
> > % perl -w -Mstrict
> > eval 'sub undefined_function { print "Hello, World\n"; }';
> > undefined_function();
> > 
> > % perl -w -Mstrict
> > sub AUTOLOAD { print "Hello, World\n"; }
> > undefined_function();
> > 
> > % perl -w -Mstrict
> > undefined_function() if main->can("undefined_function");
> 
> Dynamic - but partly compiled. Why the compiler can not detect simple
> cases (not eval/AUTOLOAD etc.)

It may detect this, but it would be incorrect to report any error when
undefined finction is called, even with "use strict; use warnings".
I use the quoted idioms in pretty much any serious project.

You may want to read 'perldoc perlcompile' and 'perldoc B::Lint'.
Accourding to the documentation, "perl -MO=Lint,undefined-subs my-prog"
should do what you want. This works in my perl 5.005 and 5.6 versions,
but strangely this same command does not report "Undefined subroutine"
in my perl 5.8.3 installation; no idea why.

You may also use 'perl -MO=Xref my-prog' to see all defined subroutines
versus the actually called ones.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list