Ahmed Moustafa wrote:
> 
> I had the following regular expression to get the extension from a file
> name:
> 
> <code>
> $extension = $filename;
> $extension =~ s/(^.+\.)([^\.]+)$/$2/;
> </code>
> 
> But it didn't work (in case the $filename didn't have an extension); so
> I had to add the following line:
> 
> <code>
> $extension = "" if (!$1);
> </code>
> 
> What is wrong with my regular expression?
> How can it be done in a single regular expression?


$ perl -e'
use File::Basename;
$filename = q|/home/someone/something.tar.gz|;
( $name, $path, $ext ) = fileparse( $filename, q/\..*/ );
print "     Path: $path\n     Name: $name\nExtention: $ext\n";
'
     Path: /home/someone/
     Name: something
Extention: .tar.gz



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to