in reply to get folder name only

There's actually a "core" module for parsing paths, see perldoc File::Basename

#! /usr/bin/perl -w use strict; use File::Basename; print dirname 'c:/mail/test2';

Replies are listed 'Best First'.
Re^2: get folder name only
by dmorelli (Scribe) on Mar 09, 2005 at 18:06 UTC
    Something was bugging me about this, basename returns nothing if the path ends with a dir separator. This will deal with that:

    #! /usr/bin/perl -w use strict; use File::Basename; # Test data my @dirs = ( 'c:/mail/test2', 'c:/mail', 'c:/mail/test2/', 'c:/mail/', ); foreach (@dirs) { print "before: $_ "; # Strip off the trailing / # Warning: may not be platform independent s|/$||; print "after: " . basename $_ . $/; }