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

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: mkdir in loop - overwrite danger?
by GotToBTru (Prior) on Dec 23, 2015 at 13:15 UTC

    I did consider that, but got lazy; replacing ls with glob meant also having to split off the basename of the file from the path. I liked the simplicity.

    Update: having looked at this again, I see glob returning file names only if that path is not included. That makes for a more portable solution.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)