in reply to Re: Get last occurence of a character in a string
in thread Get last occurence of a character in a string

You're giving the opposite of what was asked for, and you should escape your backslashes (in the assignment)
my $path = 'c:\\folder1\\filename.doc'; my ($file) = ($path =~ /([^\\]*)$/);
(And yes, File::Basename is the way to go in this case)

UPDATE: Corrected /([^//]*)$/ to /([^\\]*)$/, thx FunkyMonk

Replies are listed 'Best First'.
Re^3: Get last occurence of a character in a string
by FunkyMonk (Bishop) on Aug 06, 2008 at 13:23 UTC
    You're giving the opposite of what was asked for
    Yes, you're right. I misread the OP's question.

    and you should escape your backslashes
    Sure?
    my ($file) = ($path =~ /([^//]*)$/);

    Unmatched [ in regex; marked by <-- HERE in m/([ <-- HERE ^/