Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Regex To Remove File Extension (rindex)

by kyle (Abbot)
on Dec 10, 2008 at 19:44 UTC ( #729492=note: print w/ replies, xml ) Need Help??


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,'.') = '';

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://729492]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2016-06-26 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (330 votes). Check out past polls.