Johnson, Reginald (GTI) wrote:
In my code I am using grep successfully,
But rather inefficient. A hash is a better tool to check for existence;
see the FAQ entry "perldoc -q contained".
but I would also like an
output file that has the objects that don't match the grep.
<snip>
while (<MHSFILE>) {
chomp($_);
push (@mhsArray, $_);
}
while ($line= <INFILE>) {
chomp($line);
print "$line\n";
@inmhs = grep/\b$line\b/i,@mhsArray;
foreach $line (@inmhs) {
print OUTFILE "$line\n";
}
} #end while
Consider this approach:
my %mhsHash = map { chomp; $_ => 1 } <MHSFILE>;
while ( my $line = <INFILE> ) {
chomp $line;
print { $mhsHash{$line} ? *OUTFILE : *OUTFILE2 } "$line\n";
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/