I was going to comment on the for loops, but duff beat me too it. Isn't it a whole lot cleaner to deal with the array elements ... and to bypass that long namespace specifying name?

Less significant, but it will trim 10 lines from your program. Instead of declaring your variables one by one, if you make a list of them by wrapping them in parentheses, you can declare them all at once:

my ( $moduleName, $netName, @gateInst, $gate, $netCap, $violation, @maxTrans, $worstTrans, $line );

You never use $j, and you don't need $i any more. As for $moduleName, the first thing you do in the loop is assign a value, so you don't need to initialize it to an empty string.

The $drc::flag if/then/else section is a great situation for using references .... you do the exact same dereferencing, but a flag decides whether you access %drc::rpt1 or %drc::rpt1. How about:

my $rpt = $drc::flag ? \%drc::rpt1 : \%drc::rpt2; $rpt->{$moduleName}{$netName}{$gate}{"Capacitance"} = $violation;

Or maybe you could cause an error to assign the right object reference to a variable, instead of setting the flag?

If there's a possibility that the bodies of the loops will expand, it's worth keeping them explicit. But if they are defined as short one-liners, consider collapsing them:

if ( $drc::file1[$i] =~ m/^\s*\Module:/i ) { $moduleName = getModuleName ( $drc::file1[$i] ) ; } # could become $moduleName = getModuleName ( $item ) if ( $item =~ m/^\s*\Modul +e:/i );

I use a bit of space before the if() to emphasis what happens, and to separate the action and the condition.

This way, the subroutine becomes: For each element in the array, do A if appropriate, do B if appropriate, ,do C if appropriate, handle errors, .....

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to Re: Hash Data Structure by TomDLux
in thread Hash Data Structure by gautam_buddha

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.