in reply to Problems with -filetest on readdir results
Your foreach loop was incorrect. Use of strict and warnings also helps spot errors.#!/usr/bin/perl
use strict;
use warnings;
my $path="/foo/bar/";
opendir (DIR, $path) or die "Could not open directory: $!";
@files = readdir(DIR);
foreach my $file (@files) {
print "$file\n";
}
You could also replace the foreach loop with a map statement:
Cheers!
print map {$_ = "$_\n";} @files;
BazB.
Update: I ignored the -d test, and obviously don't know my foreach loop from my elbow. Oops. ides++ and boo_radley++
|
---|
In Section
Seekers of Perl Wisdom