Perl Grep Exclusion -


i'm grepping values list of legitimate file names there file name matches i'm trying exclude. can't quite figure out exclusions.

list = (   "filea",   "makefile.am.cppcheck",   "makefile.am.cpplint",   "readme-autotools.md",   "readme-metrics.md",   "readme.md",   "autogen.sh",   "configure.ac",   "test.pl",   )    @files = grep(/(?!readme|makefile)([a-z]\.[a-z])/i,@list);   

the grep works fine without exclusion missing exclude items matching (readme|makefile) or other patterns?

edit: filenames must include period (such test.pl), hence reason exclusions opposed weeding out unwanted names alone.

it's "magic regex" again, that's expected move earth in single pattern

it's hard tell question result want, looks want file has dot in name doesn't start readme or makefile

so write that. after all, that's how .gitignore works: it's list of files or file patterns ignore, it's not 1 long super-complicated glob expression

this way others, , in 6 months' time, able make out code

use strict; use warnings 'all'; use feature 'say';  @list = qw/     filea       makefile.am.cppcheck       makefile.am.cpplint       readme-autotools.md       readme-metrics.md       readme.md       autogen.sh       configure.ac       test.pl   /;  @filtered = grep {     /\./ , not /^readme/i , not /^makefile/i; } @list;  @filtered; 

output

autogen.sh configure.ac test.pl 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -