Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Searching Multiple directories???

by calebcall (Sexton)
on Oct 20, 2011 at 02:01 UTC ( #932541=perlquestion: print w/ replies, xml ) Need Help??
calebcall has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write something that will search multiple directories. Say my script is called findem.pl, I want to be able to pass it multiple arguments and have it search each one for something specific. Example:
# ./findem.pl /home/me /home/you
Right now It will only search through the first directory. Below is what I'm using right now to do this. I'm using Find::File::Rule which if I'm reading correctly, is supposed to be able to accept an array. I don't doubt that I'm doing something wrong. (I'm a complete newb at this stuff)
#!/usr/bin/env perl use strict; use warnings; use File::Find::Rule; my @files = find( file => name => [qw/ *.mkv *.avi / ], in => @ARGV ); foreach my $infile (@files) { print $infile . "\n"; }
I've tried manually building my array (i.e. changing @ARGV to @dirs and using my @dirs = ("/home/me","/home/you"); ) and it still does not work, so I'm thinking it's something with how I'm trying to use the directories. Any suggestions?

Comment on Searching Multiple directories???
Select or Download Code
Re: Searching Multiple directories???
by GrandFather (Cardinal) on Oct 20, 2011 at 02:14 UTC

    Try passing an array reference as the value for 'in':

    in => \@ARGV

    Otherwise the first element is treated as the directory to search and the remaining elements are treated as parameters to find.

    True laziness is hard work
      Wow, something as simple as a \, that worked perfectly. I wish I knew what exactly that did, guess I need to go research what an array reference is :) Thanks!
        You could consider arming yourself with some of the many wonderful Perl books around as well:
        
        Effective Perl Programming - D'Foy et al
        Conway's OO Perl
        MJD's Higher Order Perl
        
        In particular I would recommend the Perl Cookbook.
        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://932541]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-12-18 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (58 votes), past polls