John Fitzgerald wrote:

> Hi, I'm fairly new to Perl, and trying to do a simple
> operation on a text file exported from excel.
> ID      Enrolled     Extraneous Columns....
> 3008    05-Aug-03
> 3008    05-Aug-03
> 3008    05-Aug-03
> 3008    05-Aug-03
> 3008    24-Sep-03
> 3009    11-Aug-03
> 3010    19-Nov-03
> 3010    11-Jul-03
> 3010    11-Jul-03
> 3010    11-Jul-03
> 3011    15-Jul-03
> As you can see, the dates for a given ID are
> different. What I need to do, is set the dates all to
> the earliest date for that ID (client-birth date). The
> other columns are are important, but don't factor in
> here. I'd appreciate any help. Thanks -John

Why are you trying to throw information away?  You are not really
specific about what you want to achieve, here, but this doesn't
make a whole lot of sense.  If you are trying to find the earliest
date that a given ID was reference you can simply take the first
and ignore the rest.

open FIRST, 'first.txt' or die "Couldn't open first access: $!";
my $line = <DATA>;
my $id = '';
while (defined $line) {
   if ($line =~ /^(\d+)\s+(\S*)/) {
      if ($1 ne $id) {
         $id = $1;
         my $date = $2;
         print  FIRST "$id    $date\n";
      }
   }
   $line = <DATA>;
}

It could be that this is all the information you want to extract.
If so, this should do it.  Otherwise, you might think about tacking
on some type of GUID [possibly auto-numbering] to identify each
line item.  Each one probably represents some unique information,
anyway.

Joseph


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


Reply via email to