Marco Centemeri wrote:
>
> Hello All,
Hello,
> I'd like to know if a file name is like namefile.ext (only one dot in the name)
> or namefile.xxx.zzzzz.ext (more than one dot in the name).
> I tried with regex:
>
> $file1='doctobepublish.new.pdf';
>
> if ( $file1 =~ /\.{2,}/ ) { print "KO filename not properly formatted"; }
> else { print "OK filename is good"; }
>
> This doesn't work and the match is true only if the two dots are consecutive.
>
> doctobepublish.new.pdf =~ /\.{2,}/ doesn't match
> doctobepublish..new.pdf =~ /\.{2,}/ match
>
> My idea, probably wrong, is that regex process scan all the string and try
> to match all the possible so
>
> doctobepublish.new.pdf =~ /\.{2,}/ should match
> anotherdoctobepublish.pdf =~ /\.{2,}/ should not match
>
> May anybody help me to solve the problem and to understand better how regex
> works?
> I've already read perlquik and perlre but some points are still foggy!
Instead of a regular expression you can use the transliteration operator
to count characters.
$ perl -le'
my @files = qw/one two.txt three.four.txt/;
for my $file ( @files ) {
if ( $file =~ tr/.// == 1 ) { print "Valid: $file" }
else { print "NOT Valid: $file" }
}
'
NOT Valid: one
Valid: two.txt
NOT Valid: three.four.txt
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]