in reply to Unix shell ls vs readdir

take a look at module File::Find, quite different approach.

Replies are listed 'Best First'.
Re^2: Unix shell ls vs readdir
by jffry (Hermit) on May 11, 2010 at 04:21 UTC

    Do you mean use it like this?

    #!/usr/bin/perl -w use strict; use warnings; use File::Find; my @inits; sub wanted { if (-l $_ && (readlink("$_") =~ /tomcat/)) { push @inits, $_ ; } } find(\&wanted, '/etc/rc.d/init.d'); print join("\n", @inits);

    I'm not really seeing what I'm gaining (aside from exposure to a very useful module). It seems like overkill, and I can't determine how to prevent it from recursively going into any subdirectories. The $options{'bydepth'} doesn't seem to do that from what I can understand of the docs.

      If you're looking for files within a single known directory, File::Find (or the recurse method of Path::Class::Dir) will be of little value to you. Their purpose is to call a subroutine for every file under a certain point. Any filtering must be done inside your subroutine.

      Options controlling depth-first or breadth-first processing of the directory tree will only effect order. No filtering would be implied.

Re^2: Unix shell ls vs readdir
by Anonymous Monk on May 10, 2010 at 19:23 UTC
    ... or the  recurse method of Class::Path::Dir...

      Err, make that Path::Class::Dir.

      Dyslexic moment. Sorry.