People have tried to explain but we are not getting thru to you, look at this
use strict; use warnings;
use LWP;
my $ua = new LWP::UserAgent();
{
# In this case you have 2 literal strings enclosed in single quotes
# with the variable $m concatenated in the middle.
# I like that way best because you are assured text is text and variab
+les are variables.
#
my $m=3;
my $uri = 'https://www.google.com/finance/converter?a='.$m.'&from=USD&
+to=EUR';
my $req = HTTP::Request->new(GET => $uri);
$req->content_type('application/json');
my $re = $ua->request($req);
$re->content =~ m|<span class=bld>(.+?)</span>|i;# and $span = $1;
my $ct = substr($1, 0, -6);
print 'ct:'.$ct."\n";
print $uri."\n";
}
{
# Here you have one string,
# but because it is in double quotes perl symbols/expressions get in
+terpolated inside.
# Some think it is cleaner,
# but things you dont expect can change
# because perl sees them as something to replace.
#
my $m=3;
my $uri="https://www.google.com/finance/converter?a=$m&from=USD&to=EUR
+";
print $uri."\n";
}
{
# a third way, as suggested by [haukex]
# In this case many problems associated with special characters in the
+ uri are avoided.
use URI;
my $m=3;
my $uri =URI->new('https://www.google.com/finance/converter');
$uri->query_form(
a => $m,
from => 'USD',
to => 'EUR',
);
print $uri."\n";
}
Notice how all 3 printed uris are the same and what you want to see
D:\goodies\pdhuck\down1\perl\monks>perl uri.pl
ct:2.78
https://www.google.com/finance/converter?a=3&from=USD&to=EUR
https://www.google.com/finance/converter?a=3&from=USD&to=EUR
https://www.google.com/finance/converter?a=3&from=USD&to=EUR
Do you get it yet? I only ran the first method but sine all 3 printed uris are the same any of the 3 methods would work the same.
|