#!/usr/bin/env perl
use warnings;
use strict;
use File::Find;
my $location="$var1/$var2/$var3/";
sub find_ksh {
my $F = $File::Find::name;
if ($F =~ /ksh$/ ) {
print "$F\n";
}
}
find({ wanted => \&find_ksh, no_chdir=>1}, $location);
Or readdir:
opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
my @files= map{s/\.[^.]+$//;$_}grep {/\.ksh$/} readdir DIR;
closedir $dh;
Both solutions are untested but they should work straight out of the box.
Update: Also if you are running linuxOS or Cygwin terminal: Update3: as monk haukex pointed out using back ticks is not a good option, read the link on his response bellow why.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $path = shift || '.';
my @files = `find $path -name '*.ksh' -o -name '*.txt'`;
chomp @files;
print Dumper \@files;
WindowsOS with Cygwin:
my @files = `find $path \( -name '*.ksh' -o -name '*.txt' \)`;
Update2: Similar question with some maybe useful answers combining regex on search see (Re: File::Find find several strings in one directory).
Hope this helps.
Seeking for Perl wisdom...on the process of learning...not there...yet!
|