file name without the extension

I want to grab the file name without the extension and without using a
module. I have a working solution with two regular expressions but I
wonder if it can be done with only one regional expression.

For all the following $node_path the $node_body should be "file".


my $node_path = 'c:/dir.1\dir2\file.bin';
my $node_path = 'c:/dir.1\dir2\file';
my $node_path = 'file.bin';


(my $node_body = $node_path) =~s/.*?([^\\\/]*)$/$1/;
$node_body =~s/\.[^\.]*\s*$//;

print $node_body; # file
George Bouras [ Mo, 03 April 2006 22:18 ] [ ID #1258513 ]

Re: file name without the extension

George Bouras wrote:
> I want to grab the file name without the extension and without using a
> module.

Can you possibly explain what reason you have for re-inventing this
wheel? When a solution already exists, and is available in the
standard distribution of Perl, why would you want to ignore it and make
an attempt to write your own?

Paul Lalli
Paul Lalli [ Mo, 03 April 2006 14:17 ] [ ID #1258514 ]
Perl » alt.perl » file name without the extension

Vorheriges Thema: arrays of arbitrary dimension?
Nächstes Thema: Trap SNMP