in reply to Re: opening directories in perl
in thread opening directories in perl

I'm having some real problems with this File::Find module!

I have read the relevent docs but am really unsure what to but in the wanted subroutine in order to find the files I want. The files I want to get are new/something_here/mlc

use File::Find; my $dir = ('new/'); find (\&wanted, $dir); # this bascially lists all the directories, how can I get it to look f +or my 'mlc' files? sub wanted { print $File::Find::dir; }

Replies are listed 'Best First'.
Re^3: opening directories in perl
by trammell (Priest) on Jul 03, 2005 at 19:50 UTC
    In the documentation I find this snippet:
    The wanted() function does whatever verifications you
    want.  $File::Find::dir contains the current directory
    name, and $_ the current filename within that directory.
    $File::Find::name contains the complete pathname to the
    file. 
    
    So I'd try this to start (untested):
    my @mlc; sub wanted { return unless $_ eq 'mlc'; push @mlc, $File::Find::name; } find(\&wanted, '.'); foreach my $file (@mlc) { open(my $fh, $file) or die "Can't open '$file': $!"; # per-file code goes here }