[Canberra-pm] how to tell if a library is available?

Jacinta Richardson jarich at perltraining.com.au
Wed Jun 18 03:06:51 PDT 2008

Kim Holburn wrote:

> I tried your constant solution.  It works fine when it can find the  
> library but produces a strange error when it can't.  So there still  
> appears to be some compiling going on.

There is.  I think it occurs when perl attempts to identify the code blocks.
The end result of compiling is:

perl -MO=Deparse test.pl
BEGIN { $^W = 1; }
sub BEGIN {
    eval 'use Text::Autoformat';
use constant ('AUTOFORMAT', $INC{'Text/Autoformat.pm'});
my $data = "\n >> That bundle of copyrights relates to the very considerable\n
>> investment required to make a succession of feature films.\n\nIt's a kind of
circular argument.  People make an investment in a\nmovie in order to make a
profit because they know they have these\ncopyrights and a bunch of people who
earn their living helping them\nprotect those copyrights.\n\n";
do {
    print "no\n"
test.pl syntax OK

Which is what we're expecting, but the warning happens before it finishes the
compile.  The problem line is this one:

>    $data = autoformat $data, { right=>$width } ;

Perl's telling you that - at first glance - this looks wrong.  Perhaps it's
interpreting it as:

	($data = autoformat $data), { right => $width };

I don't know exactly what it's doing, but it's seeing your hash reference as a
constructor in void context.  You can make this error go away, just by giving
Perl another hint of what you mean:

	$data = autoformat( $data, { right=>$width } );

Now there's no error.  :)  I always recommend using parentheses around your
arguments for all non-core subroutines.  It makes hitting this kind of warning
pretty much impossible.

All the best,


   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
 (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |

More information about the Canberra-pm mailing list