From: "Johnson, Reginald \(GTI\)" <[EMAIL PROTECTED]>
> In my code I am using grep successfully, but I would also like an
> output file that has the objects that don't match the grep. I am trying
> to capture the $line of my <INFILE> that don't match.
> I am thinking something like if ([EMAIL PROTECTED] =
> grep/\b$line\b/i,@mhsArray)
> { }
>
> #!/usr/bin/perl
> use warnings;
>
> $file="/adsm/CRONJOBS/MHS/nodes_cleanedup";
> $mhs="/adsm/CRONJOBS/MHS/mh_alloc.csv";
> $file_out="/adsm/CRONJOBS/MHS/in_mhs";
>
> open (INFILE, "<", "$file") or
> die "$file could not be opened: $!";
> open (MHSFILE, "<", "$mhs") or
> die "$mhs could not be opened: $!";
> open (OUTFILE, ">", "$file_out") or
> die "$file_out could not be opened: $!";
>
> while (<MHSFILE>) {
> chomp($_);
> push (@mhsArray, $_);
> }
> while ($line= <INFILE>) {
> chomp($line);
> print "$line\n";
> @inmhs = grep/\b$line\b/i,@mhsArray;
my (@found, @other);
foreach my $mhs (@mhsArray) {
if ($mhs =~ /\b$line\n/i) {
push @found, $mhs;
} else {
push @other, $mhs;
}
}
> foreach $line (@inmhs) {
> print OUTFILE "$line\n";
> }
> } #end while
> close(INFILE);
> close(MHSFILE);
You do want to treat the lines in INFILE as regexps? I guess not! I
think you want
/\b\Q$line\E\b/
or maybe you want to turn the code around and read the INFILE first
and then read the MHSFILE line by line ... which one is biger?
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/