in reply to url get with string

inside single quotes the $ is just more text, not the start of a variable name

Try

my $req = HTTP::Request->new(GET => "https://www.google.com/?name=$nam +e");
or
my $req = HTTP::Request->new(GET => 'https://www.google.com/?name='.$n +ame);

Replies are listed 'Best First'.
Re^2: url get with string
by bigup401 (Pilgrim) on Mar 23, 2017 at 09:07 UTC

    i tried it bt failed. lets say if the link is like this

    $fname = "john"; $lname = "doe"; $ctry = "canada"; my $req = HTTP::Request->new(GET => 'https://www.google.com/?firstname +=$fname&lastname=$lname&country=$ctry')

    but works with no $ string

    my $req = HTTP::Request->new(GET => 'https://www.google.com/?firstname=john&lastname=deo&country=canada')

      Try splitting up your problem in two parts:

      $fname = "john"; $lname = "doe"; $ctry = "canada"; my $url = 'https://www.google.com/?firstname=$fname&lastname=$lname&co +untry=$ctry'; print "Requesting ", $url, "\n"; my $req = HTTP::Request->new(GET => $url);

      Also, you might want to learn about single and double quotes and how they differ in behaviour:

      my $single_quoted = 'https://www.google.com/?firstname=$fname&lastname +=$lname&country=$ctry'; my $double_quoted = "https://www.google.com/?firstname=$fname&lastname +=$lname&country=$ctry"; print 'Single quotes:', $single_quoted, "\n"; print "Double quotes:", $double_quoted, "\n";

      It fails because you are still using single quotes.