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

Hi I can just download web page content using the following statement without zip/unzip ::
my $content = get $regd_web_url;
How to zip and unzip a page in a subroutine ?? When i execute the following code placed in a subroutine, the below error occurs :

Can't call method "get" on an undefined value


This is the code, which i executed :
#--------------Zipping n Unzipping is done here # download page section first zip then unzip my %headers = ('Accept-Encoding' => ' gzip;deflate'); my $response = $ua->get($regd_web_url, %headers); my $content = $response->content; if(my $encoding = ($response->content_encoding)) { $content = Compress::Zlib::memGunzip($data) if $encoding =~ /gzip/i; $content = Compress::Zlib::uncompress($data) if $encoding =~ /deflate/ +i; }
-Regards
Sugar

Replies are listed 'Best First'.
Re: How to zip and unzip a page in a subroutine ??
by tirwhan (Abbot) on Dec 19, 2005 at 13:50 UTC

    Your variable $ua is empty, this needs to contain an LWP::UserAgent object.

    my $ua = LWP::UserAgent->new; my $response = $ua->get($regd_web_url, %headers);

    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
Re: How to zip and unzip a page in a subroutine ??
by matija (Priest) on Dec 19, 2005 at 13:48 UTC
    I think your problem is that $ua is NULL

    That's not to suggest ther may not be problems with your method of compression/decompression, but it's not the source of the error.

      I think your problem is that $ua is NULL
      This is Perl monks, not C monks. There's no NULL in Perl, except as a user definable indentifier. Perl has undef though, and that's probably what you mean.
      Perl --((8:>*
Re: How to zip and unzip a page in a subroutine ??
by Perl Mouse (Chaplain) on Dec 19, 2005 at 13:50 UTC
    That means that $ua contains an undefined value. Which, if the code you quote is all the code you have, is indeed the case. $ua isn't set.
    Perl --((8:>*