in reply to Optimization of script
I'm assuming the accounts in the control file are in the same order in the csv files and that the records matching the 'AccountInProcess' in the csv files are one sfter the other (if there are more than 1 record in the csv file matching the 'AccountInProcess').
I think the the seek statements are wrong and they may be the reason for the slow down. They are seeking backwards more than 1 line.
seek $LoanPaymentCalendarFileHandle, -$file_seek_calendario_pago[0], 1 +;
I think you need
This version of seek will position the file to start reading on the line immediately after the last successful match which is what you want. Your seek moves it way back to near the beginning of the file. So, you are effectively rereading the whole file from the beginning each time.seek $LoanPaymentCalendarFileHandle, $file_seek_calendario_pago[0], 0;
There are a few items in your program that could be improved.
These variables could all be declared as scalars instead of declared as arrays. You don't use them as arrays in your program anyway.# counters everywhere my @counter_tran_prestamo = 0; my @counter_cuentas_prestamo = 0; my @counter_calendario_pago = 0; my @prev_account = '0'; my @counter_accounts_per_file = 0; my @counter_files = 0; my @found_calendario_pago = 0; my @found_trans = 0; my @file_seek_tran_prestamo; my @file_seek_cuentas_prestamo; my @file_seek_calendario_pago;
So you could say, for instance, $found_calendario_pago = 0; instead of $found_calendario_pago[0] = 0;. (The same for all the other counters and flags.)
Declared like this, instead:
my $counter_tran_prestamo = 0; my $counter_cuentas_prestamo = 0; my $counter_calendario_pago = 0; my $prev_account = '0'; my $counter_accounts_per_file = 0; my $counter_files = 0; my $found_calendario_pago = 0; my $found_trans = 0; my $file_seek_tran_prestamo; my $file_seek_cuentas_prestamo; my $file_seek_calendario_pago;
|
|---|