#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); my %fdates = ( FBBv0 => "conv_dicom_fbb_v0_date.csv", FBBv2 => "conv_dicom_fbb_v2_date.csv", MRIv0 => "conv_dicom_mri_v0_date.csv", MRIv2 => "conv_dicom_mri_v2_date.csv", ); my %ofiles = ( FBBv0 => "facehbi_fbb_v0_date_a.csv", FBBv2 => "facehbi_fbb_v2_date_a.csv", MRIv0 => "facehbi_mri_v0_date_a.csv", MRIv2 => "facehbi_mri_v2_date_a.csv", ); my $info_file = "internos.csv"; my %internos; open IIF, "<$info_file"; while(){ if(/(F.*);(.*)/){ (my $fnumber, my $inumber) = /(F.*);(.*)/; $internos{$fnumber} = $inumber; } } close IIF; my %dates; foreach my $fdate (sort keys %fdates){ open IDF, "<$fdates{$fdate}" or die "NO such file!"; while(){ if(/(F.*);(.*)/){ (my $fnumber, my $date) = /(F.*);(.*)/; (my $cdate = $date) =~ s/(\d{4})(\d{2})(\d{2})/$3.$2.$1/; $dates{$fnumber}{$fdate} = $cdate; } } close IDF; open ODF, ">$ofiles{$fdate}"; print ODF "FACEHBI; Interno; Fecha\n"; foreach my $fnumber (sort keys %internos){ print ODF "$fnumber; "; if (exists $internos{$fnumber}){ print ODF "$internos{$fnumber}; "; if (exists($dates{$fnumber}) && exists($dates{$fnumber}{$fdate})){ print ODF "$dates{$fnumber}{$fdate}\n"; }else{ print ODF "NA\n"; } } } close ODF; }