http://www.perlmonks.org?node_id=147189

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

Seems simple enough, but what is the best platform-independent way to get the directory for a given file path?

I want a simple program that is given a list of files (say, output from "find") and for each file, prints the containing directory.

For example:

  $ pwd
  /home/mobiGeek
  $ perl dirs.pl  ../foo.html /etc/passwd /a/b/c/smile.gif
  /home
  /etc
  /a/b/c
Thanks in advance,
mobiGeek.