in reply to How to search recursively and return specific patterns

Something along these lines should do the job I think:
#!/usr/bin/perl use strict; use File::Find; my @dirs = @ARGV or die "Please supply a valid directory to search"; find(\&wanted, @dirs); sub wanted{ if(-f && m/\.(mp3|rm)$/){ print "$File::Find::name\n"; } }
Update: Thanks to andreas1234567 for suggesting I add a -f test to avoid printing non-files. I guess, it's unlikely to find anything other than a file that ends ".mp3" or ".rm", but best to be on the safe side!

Replies are listed 'Best First'.
Re^2: How to search recursively and return specific patterns
by dilip_val (Acolyte) on Aug 24, 2007 at 14:34 UTC
    Thanks guys for all your replies , i was not able to use File::Find:Rule or File::Find::Match as it is not present in the perl distribution we use. The last suggested script works for me. Would like to understand what m and $ stand for inside the if condition . if(-f && m/\.(mp3|rm)$/) Thanks again, Jude Dilip.
        Thanks Chris and Thanks Again to everyone for helping me out. Cheers Jude