Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::FTP and variables

Status
Not open for further replies.

perlnovice

Technical User
Feb 22, 2001
3
US
I know this must be a very simple question, but how do you pass a variable?

For example, this doesn't work when I try it:
$variable = somefile;


$ftp->get("$variable");


Any help would be much appreciated.
--Perlnovice
 
when assigning to a variable, you shouldn't use barewords, so try:[tt]
$variable = "somefile";
$ftp->get("$variable");[/tt]
"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
If I wanted to make the variable a regular expression, would that still be enclosed in double quotes?

perlnovice
 
"...make the variable a regular expression..."
um, if you want to use a variable in a regular expression, you can do the following:[tt]
$var = "someword";
if ($string =~ m~$var~) {do stuff}[/tt]


in general, barewords should only be subroutine calls. if you want to assign a string to a variable, put some sort of quotes around it(well, not backtiks). "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Sorry about the my unspecific question. Actually, what I wanted to know was how to use the FTP module to get a file that matches a certain pattern. I wanted to know whether you can pass a pattern as a variable. I only know how to get a specific file name via

$ftp->get($variable)

but is it possible to make that variable a regular expression so that it ftp's anything that matches a pattern I choose?

 
you could much easier call $ftp->ls() and regex the return from that to make sure you get files that actually exist. try something like:[tt]
my @ls = $ftp->ls();
foreach (@ls)
{
if (m~pattern~)
{
$ftp->get($_);
}
}[/tt]
"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
There is also a kind of quote operator specifically for regular expression. Read up on the qr() operand in the perlop manpage.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top