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;

In reply to Re: Optimization of script by Cristoforo
in thread Optimization of script by JulioRD

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.