rodee
rodee

Reputation: 3171

using wildcard in the dir locations and find all files with an extension

my @hex_locations = ("$FindBin::Bin/../../../project/platform-fsm9900_cdp-full/build-target/gnss-1.0.0",
                     "$FindBin::Bin/../../../project/platform-fsm9900_cdp-base/build-target/gnss-1.0.0"); 

instead of these 2 lines, can I specify it in single line with a wildcard as below? "$FindBin::Bin/../../../project/platform-fsm9900_cdp-*/build-target/gnss-1.0.0"

my @hex_dep_files;

sub find_dep_files {
    my $F = $File::Find::name;
    if ($F =~ /.d$/ ) {
        push(@hex_dep_files,$F)
    }
}

for my $loc (@hex_locations) {
   find({ wanted => \&find_dep_files, no_chdir=>1}, $loc);
}

with above for loop, I am getting all the *.d files from the @hex_locations, can I do it in single function instead of calling a separate function called "find_dep_files", I don't want to call a different function from this for loop so I need not define the array @hex_dep_files as global.

Thanks for all the help.

Upvotes: 1

Views: 1257

Answers (2)

ikegami
ikegami

Reputation: 386386

To answer the actual question.

my @hex_dep_files;
for my $loc (@hex_locations) {
   find({
      no_chdir => 1,
      wanted => sub {
         my $F = $File::Find::name;
         return if $F !~ /.d$/;
         push @hex_dep_files, $F;
      },
   }, $loc);
}

or

my @hex_dep_files;
find({
   no_chdir => 1,
   wanted => sub {
      my $F = $File::Find::name;
      return if $F !~ /.d$/;
      push @hex_dep_files, $F;
   },
}, @hex_locations);

Upvotes: 2

fugu
fugu

Reputation: 6578

Can't you just use glob:

my @files = </path/to/files/*.extension>;

Upvotes: 2

Related Questions