Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Unix shell ls vs readdir

by jffry (Hermit)
on May 11, 2010 at 04:21 UTC ( [id://839361]=note: print w/replies, xml ) Need Help??


in reply to Re: Unix shell ls vs readdir
in thread Unix shell ls vs readdir

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.

Replies are listed 'Best First'.
Re^3: Unix shell ls vs readdir
by Anonymous Monk on May 11, 2010 at 14:42 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://839361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-24 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found