#!/usr/bin/perl use strict; use warnings; use NEURO4 qw(load_project); my $proj = shift; unless ($proj) { print_help $ENV{'PIPEDIR'}.'/doc/update_db.hlp'; exit;} my %std = load_study($proj); my $src_dir = $std{'SRC'}; my $ids_file = $std{'DATA'}.'/ids.csv'; # Este es solo para funcionamiento interno my $proj_file = $std{'DATA'}.'/'.$proj.'_mri.csv'; #Leo los que han subido my @orig_str = qx/ls $src_dir/; chomp @orig_str; #Leo el DB previo my %idsinfo; my $idscount; #Pero solo si existe! if (-e $ids_file){ open IDS, "<$ids_file" or die $!; while(){ chomp; my ($key, $value) = split(/,\s?/); $idsinfo{$key} = $value; $idscount = $value; } $idscount++; close IDS; } my @not_in_db = grep !$idsinfo{$_}, @orig_str; foreach my $guy (@not_in_db) { $idsinfo{$guy} = $idscount; $idscount++; } #Update para todo open IDS, ">$ids_file" or die $!; open PDS, ">$proj_file" or die $!; foreach my $guy (sort {$idsinfo{$a} <=> $idsinfo{$b}} keys %idsinfo) { print IDS $guy,",",$idsinfo{$guy},"\n"; printf PDS "%04d;%s\n", $idsinfo{$guy}, $guy; } close PDS; close IDS;