regex - Perl: grep is matching when it should not -
sub process_ignore{ $col_ref = shift; $ignore_ref = shift; foreach ( @{$ignore_ref} ) { if ( grep( /^$_$/, @{$col_ref})) { print "will ignore column: $_\n" if $debug; } else { print "will not ignore column: $_\n because not valid column" if $debug; } } if ($debug) { foreach $val ( @{$col_ref} ) { print "$val\n"; } } } &process_ignore(\@cols, \@ignores)
--
@cols have a_id, status, stime
@ignores have a_id, sdd
output:
ignore column: a_id
ignore column: sdd
a_id status
stime
i m not sure why going the matching if block when should not.
there no sdd in @cols
also, grep ignore case? i.e a_id vs a_id?
replace:
foreach ( @{$ignore_ref} ) { if ( grep( /^$_$/, @{$col_ref})) {
to(at least):
foreach $ignore ( @{$ignore_ref} ) { if ( grep( /^$ignore$/, @{$col_ref})) {
or even(if regexp not necessary):
foreach $ignore ( @{$ignore_ref} ) { if ( grep {$_ eq $ignore} @{$col_ref} ) {
Comments
Post a Comment