TehJiBuey
asked on
Replacement of filename in variable
A filename is stored in the associative array "$fname{$key}". For eg, either ".gif or .jpg" file.
Then how do i extract only this ".gif or .jpg out" from the variable??
This is because I want to replace the filename wif another name(.gif or .jpg).
Then how do i extract only this ".gif or .jpg out" from the variable??
This is because I want to replace the filename wif another name(.gif or .jpg).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
($Ext) = $fname{$Key} =~ m/\.(.*)$/;
File::Basename
This module will allow for more than 1 dot in the file name
use File::Basename;
($name,$path,$suffix) = fileparse($fullname,'\..*' );
If you want to limit the type of extentsions
($name,$path,$suffix) = fileparse($fullname,('\.jp g','\.gif' ));
use File::Basename;
($name,$path,$suffix) = fileparse($fullname,'\..*'
If you want to limit the type of extentsions
($name,$path,$suffix) = fileparse($fullname,('\.jp
ASKER
thank u so much for all ur help!!
($Name, $Ext) = split (/./, $fname{$key});
# The file name is stored in $Name and the extension is stored in $Ext.
# if you want to join it again,
$FileName = join('.',($Name,$Ext));
Hope it helps.