Avisekh Das
Avisekh Das

Reputation: 161

how to pass value using a variable in an URL while executing this URL by perl scripting

I am trying to execute an URL through perl scripting. In that initially I am keeping some value in a text file and setting value in file as an argument.

#!/usr/bin/perl
use warnings;

open my $fh, '<','output_perl.txt' or die "Failed: $!\n";
my $text1 = do {
    local $/;
    <$fh>
};
close $fh or die "Failed again: $!\n";


open my $i, '<','output_perl_1.txt' or die "Failed: $!\n";
my $text2 = do {
    local $/;
    <$i>
};
close $i or die "Failed again: $!\n";


open my $j, '<','output_perl_2.txt' or die "Failed: $!\n";
my $text3 = do {
    local $/;
    <$j>
};
close $j or die "Failed again: $!\n";

So when I am try printing the variable $text1, $text2, $text1 the value stored in output_perl.txt, output_perl_1.txt, output_perl_2.txt are getting reflected. That mean if I add below it works fine:

print $text1;
print $text2;
print $text3;

but I am running one URL in which I want want to pass the value of $text1/2/3:

use LWP 5.64;
my $browser = LWP::UserAgent->new;
my $url = 'http://sms.apps.example.com/http/sendPlainText?$text1 $text2 $text3'

The URL is working completely fine but value is not getting passed. When the URL is getting executed we can still see $text1 $text2 $text3, but I sould have see the value what it getting printed by above command.

Upvotes: 1

Views: 730

Answers (1)

reo katoa
reo katoa

Reputation: 5801

Use double quotes to interpolate variables into a string. When you use single quotes, the resulting string is literally what you typed. This goes for variables as well as metacharacters such as \n, \t, etc.

Read more here.

Upvotes: 5

Related Questions