CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
[perl] substituting variables

 



blacksun
Novice

Dec 17, 2008, 12:46 AM

Post #1 of 4 (777 views)
[perl] substituting variables Can't Post

I use plink to do ssh under windows.

The following code works:

Code
$cmd='plink.exe user@server.com /bin/test.pl 2>&1'; 
open(CMD, "$cmd |");
while(<CMD>){
print $_;
}


The following doesn't: $server is not substituted

Code
$server = 'user@server.com'; 
$cmd='plink.exe $server /bin/test.pl 2>&1';
open(CMD, "$cmd |");
while(<CMD>){
print $_;
}


Can you give me the correct way to substitute user@server.com in $server.


FishMonger
Veteran / Moderator

Dec 17, 2008, 6:58 AM

Post #2 of 4 (769 views)
Re: [blacksun] [perl] substituting variables [In reply to] Can't Post

If you need variable interpolation, then you need to use one of Perls quoting methods that allow interpolation.

$cmd="plink.exe $server /bin/test.pl 2>&1";

or
$cmd=qq(plink.exe $server /bin/test.pl 2>&1);


blacksun
Novice

Dec 18, 2008, 2:50 AM

Post #3 of 4 (759 views)
Re: [FishMonger] [perl] substituting variables [In reply to] Can't Post

try it: both ways do not work with plink.exe. Why not?


Code
#doesn't work... 
$server = 'user@server.com';
$cmd=qq(plink.exe $server /bin/test.pl 2>&1);
open(CMD, "$cmd |");
while(<CMD>){
print $_;
}



(This post was edited by blacksun on Dec 18, 2008, 2:51 AM)


FishMonger
Veteran / Moderator

Dec 18, 2008, 6:12 AM

Post #4 of 4 (753 views)
Re: [blacksun] [perl] substituting variables [In reply to] Can't Post

You need to be more specific.

What doesn't work, the variable interpolation or your plink command, or the test.pl script?

As you can see from my test, the interpolation works.

Code
C:\testing>type mytest.pl 
#!/usr/bin/perl

use warnings;
use strict;

my $server = 'user@server.com';
my $cmd=qq(plink.exe $server /bin/test.pl 2>&1);

print $cmd;

C:\testing>mytest.pl
plink.exe user@server.com /bin/test.pl 2>&1


What does the test.pl script do?

What output do you get?

Do you have warnings and strictures enabled?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives