in reply to Running find.exe for multiple extensions

I'd use File::Find

use File::Find; use strict; use warnings; find(sub { print $File::Find::name if /\.(?:h|c|sh)$/; }, '.');

Replies are listed 'Best First'.
Re^2: Running find.exe for multiple extensions
by Anonymous Monk on Apr 29, 2011 at 23:13 UTC

    Ya,I would also,but the thing is I need to grep for a variable,say $x in the resulting find.I am not able to combine both find and grep.Can you pls advise?

    These are my needs 1.Find all .h,.c,.sh and put in an array 2. Grep for $x for each array member(from above find list)and put in an array

      Any logic you can do in a shell, you can do using pure perl as well.

      I don't know what $x is, but there's no reason why you can't test against a mysterious $x variable as well.

      use File::Find; use strict; use warnings; my $x = shift; my @array; find(sub { push @array, $File::Find::name if /\.(?:h|c|sh)$/; }, '.'); my @x_files = grep {/\Q$x\E/} @array;