1833875 Members
1639 Online
110063 Solutions
New Discussion

Another Perl Question

 
SOLVED
Go to solution
Jason Berendsen
Regular Advisor

Another Perl Question

I am trying to get the following code to work. It works fine if I hard code the file to get on the ftp get line (development.exp.100102). When I try to use the variables populated with the date it no longer works. How can you use Net::FTP and still use variable names?

Thanks,
Jason

use Net::FTP;

chomp ($today=`date /T`);
$today =~ s/\D//g;
$year = substr($today,6,2);
$monthday = substr($today,0,4);
$today = "$monthday$year";

$ftp = Net::FTP->new("ftpserver");
die "Could not connect: $!" unless $ftp;
$ftp->login('anonymous', 'myemail');
$ftp->cwd('/pub');
$ftp->get('development.exp.$today');
$ftp->quit();
4 REPLIES 4
Rodney Hills
Honored Contributor
Solution

Re: Another Perl Question

Change
$ftp->get('development.exp.$today');

to
$ftp->get("development.exp.$today");

single quotes within perl will not do data interpolation. Double quotes do...

HTH

-- Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: Another Perl Question

get('development.exp.' . $today)

OR

my $xxvar = sprintf("development.exp.%s",$today);
get($xxvar);


either way will work. You were trying to concatenate inside quotes and that dog won't hunt.
If it ain't broke, I can fix that.
Jason Berendsen
Regular Advisor

Re: Another Perl Question

I should have caught that one. Thanks for the help.
A. Clay Stephenson
Acclaimed Contributor

Re: Another Perl Question

Hi again Jason:

I might as well tell you that you should also use the status method to get the status of your last FTP operation. You are really not using Net::FTP to its full advantage if you don't do the very easy error checking.

e.g.

use constant GOOD_XFER => 2;

$ftp->get($fname);
my $stat = $ftp->status;
if ($stat != GOOD_XFER)
{
printf("Get failed. Status %d\n",$stat);
}
else
{
printf("Everything OK!!!\n");
}
If it ain't broke, I can fix that.