in reply to Help with null string behavior in regex?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Help with null string behavior in regex?
by McMahon (Chaplain) on May 03, 2004 at 22:45 UTC | |
|
Re: Re: Help with null string behavior in regex?
by Eimi Metamorphoumai (Deacon) on May 04, 2004 at 19:34 UTC |