On Jun 1, 12:04 pm, [EMAIL PROTECTED] (Ben Edwards) wrote:
> Thanks everybody for there help, did a little more dinging and came up with:-
>
> eval {
> $ftp = Net::FTP->new( $remote_host ) or die "faild to connect to
> $remote_host";
> $ftp->login( $remote_user, $remote_password ) or die "failed to
> login $remote_user";
> $ftp->cwd( $remote_dir ) or die "fail to cwd to $remote_dir";
> my @f = $ftp->ls or die "failed to ls $remote_dir";
> foreach $file ( @f ) {
> if ( $file =~ /$flist/ ) {
> print LOGFILE " Getting $file";
> $ftp->get( $file, $local_dir ) or die "failed to get $file";
> } else {
> print LOGFILE " Skipping $file";
> }
> }
> $ftp->quit;
> };
>
> if ($@) {
> print LOGFILE "Error:[EMAIL PROTECTED]";
> return(1);
> }
>
> Witch almost works. The problem is:-
>
> if ( $file =~ /$flist/ ) {
>
> Which gived the error:-
>
> Error:Quantifier follows nothing in regex; marked by <-- HERE in m/*
> <-- HERE .csv/ at ./subs2pubsub_cron.pl line 786.
>
> The variable $flist has something like '*.cvs' in it which I guess is
> almost but not quite a regular expresion.
It's not a regular expression at all. It's a fileglob pattern,
intended to be parsed by the shell, not by perl.
> Any idea how I can find out if $file matches the filename 'mask'
> $flist. Alternatively is there a way of doing a ls and specifying a
> file mask?
This is an XY problem. You have problem X, you've decided upon
solution Y, and you're asking us how to do Y instead of how to solve
X. Fortunately, unlike most XY problems, you've actually told us what
X is - You have a fileglob pattern where you want a regular
expression.
1) Preferred solution - start off with a regexp to begin with. Where
is $flist coming from? Change your code so that $flist is assigned to
qr/.*\.csv$/ rather than "*.csv". If that's not possible for your
situation, see Solution #2:
2) Translate the fileglob to a Perl regexp. Here's the subroutine the
builtin find2perl uses to do just that:
sub fileglob_to_re {
my $x = shift;
$x =~ s#([./^\$()])#\\$1#g;
$x =~ s#([?*])#.$1#g;
"^$x\\z";
}
Paul Lalli
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/