{

   my $inline;

   my @usedline = {};

 

sub getme

# getme returns the appropriate line from the intermediate file (opened as

# INFILE) based on the field name requested in fld_name. It returns the

# whole line. If it CAN NOT find the field specified it returns a NULL string.

#

{

  local($line);

  local($needline) = @_; 

  local($openagain) = 0;

  local($retval) = "";

 

  RECKBLK:

  {

    while ($line = <INFILE>)

    {

       $inline++;

       if (!$usedline[$inline])

       {

         if ($line =~ /$needline/)

         {

           $retval = $line;

           $usedline[$inline] = 1;

           last;

         }

       }

    } # end of <INFILE> reached.

    #

    # the next section either returns the found line, or if none is found

    # resets the file pointer and sweeps the file another time, but ONLY           

    # once. If nothing is found, it returns an empty (NULL) $retval.

    #

    if ($retval)

    {

      return $retval;

      # $retval is not null here.

    } else {

      if ($openagain)

      {

        return $retval;

        # $retval is null here.

      } else {

        $openagain = 1;

        $inline = 0;

        seek(INFILE, 0, 0);

        redo RECKBLK;

      }

    }

  } # end of RECKBLK

 

}

}