How to list files with .c and .h in a directory with Perl regex -


how list files .c , .h files in directory.
presently using if(m/.\.c$/) giving .c files. need regex both .c , .h files.

in perl, can list files .c , .h extension directory following code:

opendir $dir, "some/path/" or die "cannot open directory: $!"; @files = grep{/\.c$|\.h$/}readdir $dir; closedir $dir; print "@files"; 

edit
if want use if(), can this:

opendir $dir, "some/path/" or die "cannot open directory: $!"; @files = readdir $dir; closedir $dir; foreach (@files) {     if (/.\.[ch]\z/s)     {         print "$_\n";     } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -