in reply to Loop Break
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_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 /
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Loop Break
by JavaFan (Canon) on Jan 19, 2012 at 16:21 UTC | |
by ww (Archbishop) on Jan 19, 2012 at 16:33 UTC |
In Section
Seekers of Perl Wisdom