in reply to Re: mkdir in loop - overwrite danger?
in thread mkdir in loop - overwrite danger?
A bit more Perlish:my $txt = "txt"; my @files = `ls *$txt`;
No need to spawn ls and hope that the shell does not ruin everything. glob can do that in pure perl:
my $txt='txt'; my @files=glob "*$txt";
Another way for this simple case (no subdirectories) would be a combination of opendir, readdir, closedir, and grep:
my $txt='txt'; opendir my $d,'.' or die "Can't opendir .: $!"; my @files=grep /\Q$txt\E$/,readdir $d; closedir $d;
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: mkdir in loop - overwrite danger?
by GotToBTru (Prior) on Dec 23, 2015 at 13:15 UTC |