monks

opendir ( SSPR , "/apps/inst1/metrica/TechnologyPacks/ON-SITE/summarys +pr/") or die "$!"; while ( defined ( $file_name = readdir(SSPR) ) ) { next if ( -d $file_name ); # removing . and .. open ( FH , "/apps/inst1/metrica/TechnologyPacks/ON-SITE/summarysp +r/$file_name" ) or die "$!"; $sspr_hash{$file_name} = []; @{$sspr_hash{$file_name}} = <FH>; map { $_ =~ s/[\n\r]//g } @{$sspr_hash{$file_name}}; }
I am using the above code to read all the files from a directory and storing it in a hashformat like, Key is the "filename" contents are its values. but it has more than 200 files each file contains more thann 2000 lines.

The hash using the above method is used as follows
# this loop is to analysed the schema from summary spr files foreach $file_name ( keys %sspr_hash ) { foreach $line ( @{$sspr_hash{$file_name}} ) { if ( grep ( /$old_schema/i, $line ) ) { print "$old_schema|$new_schema_str|$found_status|$migr +atestr|$rename_str|$file_name\n"; } } }
In the above code each filename is read in a loop and the lines are read using another inner loop. The performance of the code is pretty slow. How can I improve the efficiency and increase the performance of code. please response me with your tips based on your experience you have met earlier with this kind of code.


In reply to Improving the efficiency of code when processed against large amount of data by greatshots

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.