Sorry if my answer sounded too harsh, I'm not a native english speaker myself

The part of the code you show seems to be quite efficient and from what I can see the author of this code knows how to program in perl. I even tried out the program (the bit you posted) on my machine and it needed just over 1 second (3 seconds on a sun blade 100) to init the hash with 50000 bogus entries and run the loop over it. Naturally with empty subroutines, so no surprise really.

What you don't show is what createEDentry and updateEDentry do. Probably that is where most of the work is done.

If you want to try yourself, here is my test code. Run it on your machine, if it takes less than 20 seconds, the problem is not in the code you have shown us.

my %used_dn=(); my %en2dn=(); my %ed_en; my %pfinfo=(); my $i=50000; while ($i>0) { $pfinfo{$i--}= "$i|Henion,David|A|Active|010474|HAWKEY,Michael G|S +C3789"; } my $log=0; $i=0; foreach my $en (keys %pfinfo) { logAndSkip(\*LOG,"Considering the entry from PeopleFirst extract: $e +n...") if ($log); # Get the PF information my @pfi=(); #reset the array @pfi=split/\|/,$pfinfo{$en}; # If employee number does not exists in ED, it looks like a creation if (!exists $ed_en{$en}) { createEDentry(\*LOG,\@pfi,\%used_dn,\%en2dn); } # Looks like an ED entry update else { updateEDentry(\*LOG,$en2dn{$en},\@pfi,\%en2dn); } } # End Foreach sub LogAndSkip {} sub createEDentry { my ($LOG,$pfi,$used,$en)=@_; } sub updateEDentry { my ($LOG,$pfi,$en)=@_; }

In reply to Re^5: Optimize my code with Hashes by jethro
in thread Optimize my code with Hashes by sukhicool

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.