#!/usr/bin/perl use strict; use warnings; my $ifile = '/home/osotolongo/facehbi/dicom_mri_v2_pre_date.csv'; my $ofile = '/home/osotolongo/facehbi/dicom_mri_v2_date.csv'; my %imgdates; open IDF, "<$ifile" or die "No such file!"; while (){ (my $subject, my $imdate) = /(.*);(.*)/; if (exists($imgdates{$subject})){ $imgdates{$subject} = $imdate unless ($imgdates{$subject} > $imdate); }else{ $imgdates{$subject} = $imdate; } } close IDF; open ODF, ">$ofile" or die "Couldn't create file"; foreach my $subject (sort keys %imgdates){ print ODF "$subject;$imgdates{$subject}\n"; } close ODF;