Angle_brackets don't work that way.
To get an array of filenames, see open, opendir Duh! Sorry, readdir, or any number of threads here (hint: Super Search with terms like "dir files" or similar).
Of course, you could make your list with
ls -la /dirpath/dir/ > file_of_names
or
dir /a /dirpath/dir/ > file_of_names
But this is, after all, a perl forum.
Moving on, your regex would (if the script worked) catch files with names like pqr.cobol so you might consider this:
#!/usr/bin/perl
use Modern::Perl;
use Diagnostics;
my (@file, $file, $filename);
@file = <DATA>;
for $file (@file) {
if($file =~ /\.c$/i) { # match only filenames ending in ".c" or ".
+C"
$filename = $file;
print "$filename\n";
}
}
__DATA__
bzz.c
bzz.doc
pqr.cobol
xyd.foo
123.1c
def.C
foo.endswithC
For the record, though, your regex does achieve a good many proper exclusions
bzz.doc \
123.1c # not matched by your regex, ++
foo.endswithC /
Update: fixed brain-fart in para 1
|