Thanks for the assistance. This is what I ended up doing. The hash is
much faster and I am getting what I require in my two output files. My
mhs file has over 26 columns and is over 27,000 lines.

#!/usr/bin/perl

         $file="/adsm/CRONJOBS/MHS/nodes_cleanedup";
         $mhs="/adsm/CRONJOBS/MHS/mh_alloc.csv";
         $file_out="/adsm/CRONJOBS/MHS/in_mhs";
         $file_not="/adsm/CRONJOBS/MHS/not_found";

        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: $!";
        open (OUTFILE2, ">", "$file_not") or
                        die "$file_not could not be opened: $!";

                %mhsHash = ();
        while (<MHSFILE>) {
                chomp($_);
            ($sa,$alloc,$host,$alltherest) = split(/\,/,$_);
                $host=uc($host);
              $mhsHash{$host} = $_;
                }
        while (  $line= <INFILE>) {
                chomp($line);
                if (exists $mhsHash{$line} ) {
                        print OUTFILE "$mhsHash{$line}\n";
                        } #end if
                else { print OUTFILE2 "$line\n"; }

        } #end while
close(INFILE);
close(MHSFILE);
close(OUTFILE);
close(OUTFILE2);

-----Original Message-----
From: Jenda Krynicky [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 09, 2008 7:30 PM
To: beginners@perl.org
Subject: Re: not grep

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/
--------------------------------------------------------

This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically indicated, 
this message is not an offer to sell or a solicitation of any investment 
products or other financial product or service, an official confirmation of any 
transaction, or an official statement of Merrill Lynch. Subject to applicable 
law, Merrill Lynch may monitor, review and retain e-communications (EC) 
traveling through its networks/systems. The laws of the country of each 
sender/recipient may impact the handling of EC, and EC may be archived, 
supervised and produced in countries other than the country in which you are 
located. This message cannot be guaranteed to be secure or error-free. This 
message is subject to terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.
--------------------------------------------------------

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to