Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Optimization of script

by Cristoforo (Curate)
on Aug 18, 2016 at 20:48 UTC ( [id://1170024]=note: print w/replies, xml ) Need Help??


in reply to Optimization of script

Like ww said, the post is pretty long to try to analyze and I can't comment on the correctness of the wooksheets you're creating.

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

seek $LoanPaymentCalendarFileHandle, $file_seek_calendario_pago[0], 0;
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.

There are a few items in your program that could be improved.

# 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;
These variables could all be declared as scalars instead of declared as arrays. You don't use them as arrays in your program anyway.

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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1170024]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2024-04-23 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found