1

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thans for a lot you checking this, but I have tried ruuninthe url by putting double quote, but the script is now hiting with like "$text1" etc, could you please nevigate where do I need to put the double quote?
Read the link I posted; that should make it clear. Put the entire string in double quotes, not just the variable names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.