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

Re: Regex pattern to find directories only with digits

by reisinge (Hermit)
on Apr 11, 2013 at 11:32 UTC ( [id://1028122]=note: print w/replies, xml ) Need Help??


in reply to Regex pattern to find directories only with digits

In case you need to search recursively, you may use the File::Find core module:

use strict; use warnings; use File::Find; # Search current dir unless dir(s) given as command line args @ARGV = qw(.) unless @ARGV; find( \&get_dirs_with_numbers, @ARGV ); sub get_dirs_with_numbers { return unless /^\d+$/; # your regex print $File::Find::name . "\n"; }

find function from File::Find scans directories in @ARGV recursively and for each file calls the referenced function (coderef) get_dirs_with_numbers. Before calling your function find by default changes to the directory being scanned and sets the following variables:

  • $File::Find::dir -- visited directory path relative to the starting directory
  • $_ -- basename of the file being visited
  • $File::Find::name -- full path of the file being visited

Well done is better than well said. -- Benjamin Franklin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found