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

Hello, maybe my problem is trivial, but I cannot find an answer. I will try to explain you what is going on.

The simplest problem to explain is when I try to download a module using cpan. I always get the error:

Fetching with LWP: ftp://mirrors.localhost.net.ar/pub/mirrors/CPAN/authors/id/whatever Use of uninitialized value in hash element at /Library/Perl/5.8.6/LWP/ +Protocol.pm line 53. Use of uninitialized value in pattern match (m//) at /Library/Perl/5.8 +.6/LWP/Protocol.pm line 56. Use of uninitialized value in concatenation (.) or string at /Library/ +Perl/5.8.6/LWP/Protocol.pm line 36. Use of uninitialized value in string eq at /Library/Perl/5.8.6/LWP/Use +rAgent.pm line 199.

The extracted lines where the errors come from are:

Protocol.pm line 53 my $ic = $ImplementedBy{$scheme}; line 56 return '' unless $scheme =~ /^([.+\-\w]+)$/; # check valid + URL schemes line 36 my $impclass = LWP::Protocol::implementor($scheme) or UserAgent.pm line 199 if ($scheme eq "https") {

So, it seems that I have a problem with the assignement of a value to the variable $scheme. Other scripts that use LWP::UserAgent and LWP::Protocol give me the same type of errors, but I write down more explicitely the problem with the cpan modules because they should be more familiar for you.

All I could find about $scheme had something to do with setting or using proxies, is that true? I have no proxies set in my configuration, or they have been assigned automatically by my ISP, I don't know about that.

So, some questions arise: what can I do to solve that problem? Where I can find more information? Where I should start reading? What is that $scheme variable?

Thank you in advance for your help.

Roger

Replies are listed 'Best First'.
Re: Uninitialized $scheme variable in LWP::Protocol and LWP::UserAgent problem
by jethro (Monsignor) on Jul 27, 2008 at 13:59 UTC
    It seems from the use in LWP::UserAgent that $scheme is just the first part of a http address, like 'https', 'http', 'file' ...

    The code in UserAgent uses the scheme of the http address it wants to access, except when it has to go through a proxy. Then it uses the scheme of the proxy instead.

    I'm only making wild guesses now, but your problem could still come from the proxy handling. You might check your environment variables, maybe there is a malformed proxy definition there:

    #bash set | grep -i proxy #csh/tcsh printenv | grep -i proxy
    I would also recommend deleting .cpan in your homedir (or roots homedir) and so resetting your configuration of cpan. Since you have these problems with other scripts too, the chance that this will help is not very high but doesn't hurt to try

    You might create a minimal LWP program (just accessing a web page), and use LWP::Debug to create a logfile. Check the logfile or post it here (together with the version of perl you are using).

    UPDATE: minor clarification

      Thank you. I discovered that my environment variables FTP_PROXY and HTTP_PROXY where been set to some value that I used at the University. I set manually those variables to qw{} and now I don't get the errors. I also could run a small script using LWP that used to fail, and it works.

      Now, I have the problem that some program is automatically setting the proxy environment variables to that value, and I have to manually reset them to reflect my actual network configurations. I have to discover which program is doing that.

      Also, I have to learn some more about proxies, and how to use them with LWP.

      Thank you again... I have now a lot of read and work, but at least I know where to start.

Re: Uninitialized $scheme variable in LWP::Protocol and LWP::UserAgent problem
by Anonymous Monk on Jul 27, 2008 at 13:03 UTC
    don't use -w, use warnings, and you won't get those warnings :)

      See Injecting a filter into warn() for more information. I fought with this for a while before it clicked. use warnings instead of -w if you don't want to report warnings from included modules.

      --MidLifeXis

Re: Uninitialized $scheme variable in LWP::Protocol and LWP::UserAgent problem
by Anonymous Monk on Jul 27, 2008 at 13:09 UTC
    upgrade LWP
      I upgraded LWP, LWP::Protocol and LWP::UserAgent, and they seem to be upgraded. I continue getting the same errors.