> In diagnosing a problem, I've discovered that this program:
> #!/usr/local/bin/perl
> use CGI qw/:standard/;
> use LWP::Simple ;
> causes this error:
> Prototype mismatch: sub main::head vs ($) at ./z.pl line 3
> If I change the program to:
> #!/usr/local/bin/perl
> use CGI;
> use LWP::Simple ;
> the error goes away.
> Does this mean you can't mix styles (function-oriented vs. object-oriented) in the 
>same program?

It means that CGI and LWP::Simple try to export the same function.
You get the warning printed because the prototype of the exported
functions does not match.

The workaround is to be more explicit in what functions you import.

   use CGI qw/:standard/;    # imports &head and a bunch of others
   use LWP::Simple qw(get);  # avoids importing &head

or if you actually want the head function from LWP::Simple and still
want to import all the :standard functions:

   use CGI qw/:standard/;
   use LWP::Simple ();       # don't import anything
   *lwp_head = \&LWP::Simple::head   # manual import (with renameing)

   # head() calls CGI's head
   # lwp_head() calls LWP's head

or you could do this:

   use CGI qw/:standard/;           # import &head and others
   BEGIN { delete $main::{head}; }  # unimport &head
   use LWP::Simple qw(head);        # import &head

or you can simply avoid importing and use always fully qualified names:

   use CGI ();
   use LWP::Simple ();

   if (LWP::Simple::head("http://www.activestate.com";)) {
       print CGI::head("ActiveState is up!"), "\n";


Reply via email to