Rajesh Dorairajan wrote:

>
> Sorry the syntax error was by mistake. It's not in the actual code.
> 

next time when you post please do not retype your script. try copy and paste 
the whole script over so you can avoid typo.

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

>> > 
>> > -----------------------
>> > #Working code
>> > 
>> > #!/usr/bin/perl
>> > use strict;
>> > use LWP::UserAgent;
>> > my $url = "http://rajeshd";;
>> >                     
>> > print_page ( $url );
>> > 
>> > sub print_page{
>> > 
>> >         my($host,$port) = @_;
>> > 
>> >         my $url = $host;
>> > 
>> >         $url .= ":$port" if($port);
>> >         
>> >         my $ua = LWP::UserAgent->new(env_proxy  => 0,
>> >                                      keep_alive => 0,
>> >                                      timeout    => 30);
>> > 
>> >         my $r = $ua->request(HTTP::Request->new(GET => $url));
>> > 
>> >         print $r->content if($r->is_success);
>> >         print $r->code,': ',$r->status_line unless($r->is_success);
>> >         print "\n";
>> > }
>> > -----------------------
>> > #Failing code
>> > 
>> > #!/usr/bin/perl
>> > use strict;
>> > use LWP::UserAgent;
>> > use XML::Simple;
>> > 
>> > my $config = XMLin( "C:/config.xml", VarAttr => 'name',
>> >                     ContentKey => '-content' );
>> > 
>> > my $url = $config->={URL_1}; #$config->{URL_1} equals
> http://rajeshd at
>> run-time
>>                     
>> print_page ( $url );
>> 
>> sub print_page{
>> 
>>         my($host,$port) = @_;
>> 
>>         my $url = $host;
>> 
>>         $url .= ":$port" if($port);
>>         
>>         my $ua = LWP::UserAgent->new(env_proxy  => 0,
>>                                      keep_alive => 0,
>>                                      timeout    => 30);
>> 
>>         my $r = $ua->request(HTTP::Request->new(GET => $url));
>> 
>>         print $r->content if($r->is_success);
>>         print $r->code,': ',$r->status_line unless($r->is_success);
>>         print "\n";
>> }

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.

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
-- 
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>


Reply via email to