Tim McGeary wrote:
> Greetings,
> 
> I am a new subscriber and I do know a little perl, but I am trying to
> pick up a lot more very quickly. I am having an issue with a
> conditional checking a regular expression
> that doesn't make sense and every book or online resource I have found
> shows the same syntax I have.
> 
> Script background:
> I have one file of 4 letter codes (e.g. PART, PBIO, PENG), one code
> per line.  I read this file into an array.
> 
> I have another file of pipe delimited data, in which one of these
> fields may include a code from the previous file or - for NULL.  This
> file is too large to read in all at once, so I am reading it in line
> by line. The problem I am having is with this section:
> 
> while (<SIRSI>) {
>      $temp = $_;
>      $counter = $counter + 1;
>      print "$counter \n";
>      foreach $code (@fundcodes) {
>         if ($temp =~ /$code/) {
>            print "$temp \n";
>            push(@fund_array, $temp);
>            last;
>         }
>      }
> }
> 
> @fundcodes is the array of codes read in from the first file
> $counter is just for my debugging purposes.
> Tim McGeary
> [EMAIL PROTECTED]
        Tim, You are working too hard.  Since the codes can have to be unqiue 
otherwise why have them twice in the first file, you should just use a hash to hold 
them vs searching through the array each time.  So your code would look something like:

        my $MyHash = ();
        while ( <FUNDCODES> ) {
                chomp;
                $MyHash->{lc($_)} = 1;
       }
#
# The above loads the hash and lower cases everything
#
        while ( <SIRSI> ) {
                chomp;
            $counter = $counter + 1;
              foreach my $MyKey ( split(/\|/, $_) ) { # you say pipe delimited, once 
hit, get out
                 if ($MyHash->{lc($MyKey)} ) {
                  print "\n";
                  push(@fund_array, $_);
                  last;
                }
                 }
       }

A start I would think.
Wags ;)


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to