Your logic in the final double loop seems strange:
LINE: for each line of the file { PATTERN: for each exclude string { if it matches the exclude string skip to the next PATTERN else print the line skip to the next LINE } }
When there are no exclude strings (either because the file was not specified, or because it was empty), the code never enters the inner loop and the line is never printed: I suspect (though it isn't entirely clear) that this is the behaviour you are seeing.
I'd expect instead logic something more like this:
LINE: for each line of the file { PATTERN: for each exclude string { if we must exclude this line skip to the next LINE } we weren't excluded by any pattern, so print the line }
If this is the logic you really wanted, you can achieve it with code something like:
LINE: foreach my $line (@file1only) { foreach my $exclude (@strings) { chomp $exclude; next LINE if $line =~ $exclude; } # we weren't excluded by any of the patterns print OUT $line; }
Hugo
In reply to Re: Help with null string behavior in regex?
by hv
in thread Help with null string behavior in regex?
by McMahon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |