dilip_val has asked for the wisdom of the Perl Monks concerning the following question:

Hi , I am new to perl and trying to search recursively from a directory C:\\songs and return all files with extension .mp3 and .rm. How can i do that ? My script below returns a single pattern within that particular directory only . Pls help.
$path = "C:\\songs\\"; chdir $path; @list = glob("*.mp3"); for $filename ( @list ) { print "$filename\n"; }

20070904 Janitored by Corion: Added code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: How to search recursively and return specific patterns
by johnlawrence (Monk) on Aug 24, 2007 at 13:16 UTC
    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!
      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.
Re: How to search recursively and return specific patterns
by FunkyMonk (Chancellor) on Aug 24, 2007 at 12:59 UTC
Re: How to search recursively and return specific patterns
by moritz (Cardinal) on Aug 24, 2007 at 12:59 UTC