I am filtering out any directories. Not sure if you need it.
#the pragmas, sorted alphabettically
use diagnostics;
use strict;
use warnings;
#the imported packages
use English;
use File::Spec::Functions;
use File::Basename;
# check if directory specified, else assumer current directory
my $dir = ( scalar(@ARGV) > 0 ) ? $ARGV[0] : curdir();
my ( @files, $file, @files_wo_extn );
opendir( DIR, $dir ) or die "Could not open $dir, $OS_ERROR";
@files = readdir(DIR) or die "Reading entries in $dir, $OS_ERROR";
closedir(DIR);
foreach $file (@files) {
#check whether the file is a directory
#need to use the directory and file to access the file
unless ( -d catfile( $dir, $file ) ) {
push @files_wo_extn, basename($file);
}
}
print join "\n", @files_wo_extn;
print "\n";
|