On 1 March 2016 at 23:23, Arghya Das <arghya0...@gmail.com> wrote:
> $dir = "c:/folder/*";
> my @files = glob( $dir );
>
> foreach (@files ){
>    print $_ . "\n";
> }


Personally, I would have used either Path::Tiny, or at least, readdir() here.

There's far few places that can lead to strange bugs and security
holes with that.

With readdir:

my $base = "C:/folder";
my $dir = opendir($base );
while ( my $entry = readdir( $dir ) ) {
     next if $entry =~ /\A..?\z/   # skip cwd and updir dirs
      printf "%s\n", $entry;
}

With Path::Tiny:

use Path::Tiny qw( path );

for my $child ( path( "C:/folder/" )->children() ) {
      print $child . "\n";
}


-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to