gitarwmn has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have a text file containting a list of file names and there directories. I am wondering how to extract just the file names from this list so that I am left with a list of the directories where these files live. Can anyone point me in the right direction? Thanks

Replies are listed 'Best First'.
Re: extracting file names
by ikegami (Patriarch) on Sep 20, 2006 at 00:11 UTC
    File::Basename
    use File::Basename qw( dirname ); my @path_list = ...; my %seen; my @dir_list = sort # Sort dirs grep { ! $seen{$_}++ } # Remove dups map { dirname($_) } # Extract dirs @path_list;
Re: extracting file names
by aufflick (Deacon) on Sep 20, 2006 at 02:25 UTC
    If that's what you want to do, and your platform is Unix (or cygwin) you don't need perl at all. Try this in any bourne-like shell (eg. bash):

    (for f in `cat full_path_list_file`; do dirname $f; done) | sort -u
    Where full_path_list_file is the name of your file. The sort -u ensures that you get a unique list (ie. duplicates removed).