http://www.perlmonks.org?node_id=729492


in reply to Regex To Remove File Extension

Just for the TIMTOWTDI, here's one using substr and rindex:

my $n = 'foo.bar.txt'; $n = substr $n, 0, rindex( $n, q{.} );

In my own code, I'd write s{ \. [^.]+ \z }{}xms

Replies are listed 'Best First'.
Re^2: Regex To Remove File Extension (rindex)
by almut (Canon) on Dec 10, 2008 at 21:50 UTC

    ...or, using substr() as an lvalue:

    substr($n,rindex $n,'.') = '';