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_namesBut this is, after all, a perl forum.
or
dir /a /dirpath/dir/ > file_of_names
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 \Update: fixed brain-fart in para 1
123.1c # not matched by your regex, ++
foo.endswithC /
In reply to Re: Loop Break
by ww
in thread Loop Break
by stallion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |