Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: opening directories in perl

by trammell (Priest)
on Jul 03, 2005 at 18:33 UTC ( [id://472052]=note: print w/replies, xml ) Need Help??


in reply to opening directories in perl

You can certainly brew up your own solution with opendir(); one other (possibly easier) solution would be to use module File::Find.

Replies are listed 'Best First'.
Re^2: opening directories in perl
by Anonymous Monk on Jul 03, 2005 at 19:24 UTC
    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; }
      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 }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found