in reply to Re: Getting the filename from full path name ?
in thread Getting the filename from full path name ?

This is not a real solution - it is not portable. Please use File::Basename. Having said that...

my $a = "foo/bar/baz"; my ($file) = $a =~ /\/(.*?)$/;
Update: Thank you Chris, the code should be:
my ($file) = $a =~ m|/([^/]+)$|;

Replies are listed 'Best First'.
Re: Re: Re: Getting the filename from full path name ?
by tachyon (Chancellor) on Apr 15, 2004 at 05:14 UTC

    Actually something like my ($file) = $path =~ m|([^/\\]+)$| will work on Win32 or *nix and will also not fail to find the filname of 'file.txt'

    cheers

    tachyon

Re: Re: Re: Getting the filename from full path name ?
by Anonymous Monk on Apr 15, 2004 at 05:01 UTC
    I believe you mean
    my ($file) = $a =~ m|/([^/]+)$|;
    Your exp matches starting with the first slash

    Chris