Code :
use strict; use warnings FATAL => 'all'; my @testdata = ('toto.txt', 'toto.new.txt', 'toto...text', 'toto.', '.toto', '.toto.', '.to.to', '.to.to.', 'to.to.', '.', '..', '...', 'toto..25.text', '.toto..25.text', 'toto..25.text.', 'toto..25..text', ); foreach (@testdata) { if (/^(.*[^.])\.([^.]+)$/) { print "File: $_\tExtension: $2 (and basename: $1)\n"; } else { print "File: $_\t No extension\n"; } }
|