tags:

views:

555

answers:

3

I have a file format which is similar to "IDY03101.200901110500.axf". I have about 25 similar files residing in an ftp repository and want to download all those similar files only for the current date. I have used the following code, which is not working and believe the regular expression is incorrect.

my @ymb_date = "IDY.*\.$year$mon$mday????\.axf";

foreach my $file ( @ymb_date) 
{

 print STDOUT "Getting file: $file\n";

 $ftp->get($file) or warn $ftp->message;

}

Any help appreciated.

Cheers

+1  A: 

I do not think regexes work like that. Though it has been awhile since I did Perl, so I could be way off there. :)

Does your $ftp object have access to an mget() method? If so, maybe try this?

$ftp->mget("IDY*.$year$mon$mday*.axf") or warn $ftp->message;
Beau Simensen
+2  A: 

It doesn't look like you're using any regular expression. You're trying to use the literal pattern as the filename to download.

Perhaps you want to use the ls method of Net::FTP to get the list of files then filter them.

foreach my $file ( $ftp->ls ) {
    next unless $file =~ m/$regex/;
    $ftp->get($file);
    }

You might also like the answers that talk about implementing mget for "Net::FTP" at Perlmonks.

Also, I think you want the regex that finds four digits after the date. In Perl, you could write that as \d{4}. The ? is a quantifier in Perl, so four of them in a row don't work.

IDY.*\.$year$mon$mday\d{4}\.axf
brian d foy
It should also be pointed out that "IDY.*\.$year$mon$mday????\.axf" is not a valid regex. qr// and quotemeta would be also be good things for the OP to read about.
jrockway
A: 

Thanks I need all the current days file. using ls -lt | grep "Jan 13" works in the UNIX box but not in the script What could be a vaild regex in this scenario?

Neel
If your FTP class has an mget method the mget solution will work. If your are using Net::FTP (or any other FTP client that has 'ls' support), the Net::FTP 'ls' solution will work. You cannot use regexes like you are trying to use them.
Beau Simensen
yep I have the FTP class. Thanks I "ll give it a shot with your answer
Neel