Hello David,

First of all, thank you very much for taking the effort to help me solve the
problem. Sorry for the delay in my reply.

> please do not top post. when you reply to any message, post 
> your respond 
> below the relevant text.
> 

Sorry about this. Will make sure I do this future.

> like i say before, your working version and failing version 
> is absolutely 
> identifical. there is no reason for the failing version to 
> fail if the 
> working vesion really works.
> 

There is a difference. I modifed the original code in order to make sure I
did not break any confidentiality agreement. Let me try to explain again. I
have an xml file that contains a list of URLs. I read  these URLs into a
hash and pass them as a parameter into the function that does LWP get. The
code (again abridged) looks like:

$config = XMLin( "config.xml", VarAttr => 'name',
                    ContentKey => '-content' );

foreach my $keys ( keys %{$config} ) {
  foreach (sort keys %{$config->{$keys}} ) {
     my $url = $config->{$keys}{$_};   #$url = "http://server:port";;
     my $retval = testURL( $url );      
  }
}

sub testURL {
    my $url = $_[0];
    my $ua = LWP::UserAgent->new(   agent   => 'Mozilla/1.0',
                                    timeout => 30,
                                );
    my $request = HTTP::Request->new('GET', $url);
    my $response = $ua->send_request($request);

    my $content = $response->content();

    if ( $response->is_success ) {
         print $response->content();
    else {
       print "Failed to get $url\n";
    }    
}

__END__

#config.xml

<HOSTS>
      <URL_1>http://vasrv1:80</URL_1>
      <URL_2>http://vasrv2:80</URL_2>
      <URL_3>http://vasrv3:80</URL_3>
      <URL_4>http://vasrv4:80<URL_4>
</HOSTS>

As already mentioned, in the code above if I substituted the line 

my $url = $config->{$keys}{$_};

with,

my $url = "http://server:port";;

the function call works just fine. If I use the former statement, I receive
a 501 error. I know it's bizzare sice the value contained in the URL (to my
naked eye) is essentially the same. I believe this might've something to do
with converting the XML file to a hash, although I still cannot quite figure
it out.

> your best bet is to use the Perl debugger to step through 
> your script and 
> make sure the variables are getting the values you expected. 
> for example, 
> assume your script is named net.pl, you can involve the debugger with:
> 
> [panda]# perl -d net.pl
> 
> and then keep hitting 's<RETURN>' until the debugger is at:
> 
> main::(net.pl:9): my $url = $config->{URL_1};
> 
> hitting 's<RETURN>' one more time so this line is executed. 
> and then type:
> 
> print "$url\n";
> 
> to see what's the real value of $url. make sure $url has 
> exactly what you 
> expect. since your script is so simple, you can also put a 
> single print 
> statement after the assignment to $url and confirm it's 
> getting the right 
> value. i suggest you learn to use the debugger:
> 
> man perldebug
> 
> david

Thanks again. I use Open PERL IDE under Windows, and I feel it's got a
extremely good UI debugger. The value I see for $url after the statement in
question is the same in both cases. I still need to try Rob's suggestion to
see the length of the value in both cases, but like I said I feel the
problem originates when I read the XML file into a hash.

> -- 
> sub'_{print"@_ ";* \ = * __ ,\ & \}
> sub'__{print"@_ ";* \ = * ___ ,\ & \}
> sub'___{print"@_ ";* \ = * ____ ,\ & \}
> sub'____{print"@_,\n"}&{_+Just}(another)->(Perl)->(Hacker)
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 

Thanks again,

Rajesh

Reply via email to