in reply to Use of special character "*" to retrieve the contents
Hello dk27,
What about some alternatives? Such as File::Find
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Use of special character "*" to retrieve the contents
by haukex (Archbishop) on Jun 07, 2017 at 13:58 UTC | |
by karlgoethebier (Abbot) on Jun 07, 2017 at 16:54 UTC | |
|
Re^2: Use of special character "*" to retrieve the contents
by marinersk (Priest) on Jun 07, 2017 at 14:09 UTC |