#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $path = shift || '.';
print Dumper traverse($path);
sub traverse {
my ($path) = @_;
my @files = `find $path -name '*.c' -o -name '*.txt'`;
return if not -d $path;
opendir my $dh, $path or die;
while (my $sub = readdir $dh) {
next if $sub eq '.' or $sub eq '..';
traverse("$path/$sub");
}
close $dh;
chomp @files;
return \@files;
}
__DATA__
$ perl file.pl
$VAR1 = [
'./counts.txt',
'./file.txt',
'./sample.c',
'./testDir/anotherSample.c',
'./test.txt'
];
####
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use Data::Dumper;
my @dirs = @ARGV ? @ARGV : ('.');
my @list;
find( sub{
push @list, $File::Find::name if -f $_
&& $_ =~ /(?:\btest\b|\bsample\b|\bChris\b)/ }, @dirs );
print Dumper \@list;
__DATA__
$ perl file.pl
$VAR1 = [
'./test.pl~',
'./sample.c',
'./test.txt~',
'./test.pl',
'./test.txt'
];
##
##
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @files;
my $path = shift || '.';
print Dumper traverse($path);
sub traverse {
my ($path) = @_;
return if not -d $path;
opendir my $dh, $path or die;
while (my $sub = readdir $dh) {
next if $sub eq '.' or $sub eq '..';
push @files, "$path/$sub"
if ("$path/$sub" =~ /(?:\btest\b|\banotherSample\b|\bsample\b)/);
traverse("$path/$sub");
}
close $dh;
return \@files;
}
__DATA__
$ perl file.pl
$VAR1 = [
'./test.pl~',
'./sample.c',
'./test.txt~',
'./testDir/anotherSample.c',
'./test.pl',
'./test.txt'
];
##
##
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $path = shift || '.';
my @files = `find $path -name '*.c' -o -name '*.txt'`;
chomp @files;
print Dumper \@files;
__DATA__
$ perl file.pl
$VAR1 = [
'./test.pl~',
'./sample.c',
'./test.txt~',
'./testDir/anotherSample.c',
'./test.pl',
'./test.txt'
];