in reply to parse file name

You can simply use split to get the filename.
#!/usr/bin/perl use strict; my $long_file = '/abc/xyz/abc.txt'; my $file = ( split( "/", $long_file ) )[-1]; print "$file\n";

Replies are listed 'Best First'.
Re^2: parse file name
by Anonymous Monk on Sep 24, 2009 at 16:50 UTC
    The scenario is, I need to get the filename and file path no matter it is in windows or unix type.

    it can be either of the below
    my $long_file = '/abc/xyz/abc.txt';
    my $long_file = '\abc\xyz\abc.txt';

    In this case File::Basename and File::Spec wont return the directory part if the file name is windows format and i am running the script from unix.

    Any Solution for this?
    Thanks, Tom

      Replace all backslashes in $long_file with forward slashes before working with $long_file. Using the tr/// operator should be the most efficient implementation.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)