×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Net::FTP and variables

Net::FTP and variables

Net::FTP and variables

(OP)
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

RE: Net::FTP and variables

when assigning to a variable, you shouldn't use barewords, so try:
$variable = "somefile";
$ftp->get("$variable");

"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

RE: Net::FTP and variables

(OP)
If I wanted to make the variable a regular expression, would that still be enclosed in double quotes?

perlnovice

RE: Net::FTP and variables

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


 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."

RE: Net::FTP and variables

Have you tried $ftp->get($variable); without the quote?

RE: Net::FTP and variables

(OP)
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?

RE: Net::FTP and variables

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:
my @ls = $ftp->ls();
foreach (@ls)
{
   if (m~pattern~)
   {
      $ftp->get($_);
   }
}

"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

RE: Net::FTP and variables

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close