Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Regex pattern to find directories only with digits

by reisinge (Hermit)
on Apr 11, 2013 at 11:32 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2023-03-28 12:01 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (67 votes). Check out past polls.