Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I get a can't call method protocol without a package or object reference in the below code. Can anyone see what I have to do to fix it?
use LWP::Simple; use CGI qw/:standard/; print header, start_html(); use CGI::Carp qw(fatalsToBrowser); my $use_stopwords = 0; my @stopwords = qw(I a about an are as at be by com de en for from how + in is it la of on or that the this to was what when where who will with und the www); #$line =~ s/\bQ$_\E\b/ **** /gi for @badwords; # james blunt you're beautiful my $url = "http://www.w3schools.com/html/html_primary.asp"; ####################################### # Gather response and header codes ####################################### my $response = head($url); my $responseline = $response->protocol(); # immediate error is here my $responsecode = $response->status_line(); my $header = $response->headers_as_string();

Replies are listed 'Best First'.
Re: can't call method 'protocol'
by borisz (Canon) on Mar 26, 2006 at 19:16 UTC
    The problem is that CGI and LWP::Simple import a head method into your namespace. A quick fix is to call
    my $response = LWP::Simple::head($url);
    instead of just head. A better fix is to use the object syntax of CGI.
    Boris
Re: can't call method 'protocol'
by GrandFather (Saint) on Mar 26, 2006 at 19:16 UTC

    That may be your immediate problem, but your first problem is:

    Prototype mismatch: sub main::head ($) vs none at C:/Perl/lib/CGI.pm line 299.

    That sort of implies that head ain't what you think it is, and most likely your $url is getting tossed away.


    DWIM is Perl's answer to Gödel