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

help needed with File::Find and arrays.

by basarix (Initiate)
on Mar 11, 2005 at 15:34 UTC ( #438680=perlquestion: print w/replies, xml ) Need Help??

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

I am making my first steps in perl, and i am faced with a lil problem. i need to work with files and dirs, but restricting the files i have to work with. therefore, i used the find2perl utility to make myself a nice perl code that would give me the files i am looking for, but in order to work with them, i need to get them into an array, so i can process them. i am not finding a way to put the results of the find search into an array. I know this is probably something very easy to solve, but i am hopelessly stuck, and need to get it solved soon..... thanx noble monks for your wisdom on this... THanx all, i have solved this issue.... u've all been a good source of help / ideas
  • Comment on help needed with File::Find and arrays.

Replies are listed 'Best First'.
Re: help needed with File::Find and arrays.
by RazorbladeBidet (Friar) on Mar 11, 2005 at 15:42 UTC
    I'm no File::Find expert, by any means, but this works for me:

    ... my @list_of_files; File::Find::find( \&add_to_list, $path ); sub add_to_list { push @list_of_files, $File::Find::name if ( /#some criteria# /); } ...
    HTH!!
    --------------
    It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs
      Thanx.... i will try it asap....
Re: help needed with File::Find and arrays.
by YuckFoo (Abbot) on Mar 11, 2005 at 16:38 UTC
    File::Find::Rule returns a list of files and uses matching criteria similar to the find command.

    YuckFind

    #!/usr/bin/perl use strict; use File::Find::Rule; use Data::Dumper; my @list = File::Find::Rule->file()->maxdepth(1)->in('.'); print Dumper \@list;
Re: help needed with File::Find and arrays.
by brian_d_foy (Abbot) on Mar 11, 2005 at 17:05 UTC

    File::Finder has a gather() method that will work for you, or you can look at some of the examples in File::Find::Closures. I try to stay away from global (or file-scoped lexicals) in these sorts of problems.

    --
    brian d foy <bdfoy@cpan.org>
Re: help needed with File::Find and arrays.
by osunderdog (Deacon) on Mar 11, 2005 at 16:56 UTC

    Here is my find example. I use this when I need to remember how to use find. Course I didn't know about File::Find::Rule! Good to know.


    "Look, Shiny Things!" is not a better business strategy than compatibility and reuse.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2023-02-03 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (27 votes). Check out past polls.

    Notices?