Hi, I wrote the following piece of code :
open(VHD,"$vhd_file") || die "Can't open $vhd_file $!\n"; while(<VHD>){ # find all the entities in the current file if (/entity\s+(\w+)\s+is/i) { $1{'name'} = $1; $1{'fname'} = $vhd_file; push @entities, \%1; } if (/architecture (\w+) of (\w+) is/i ... /end $1\;/i) { # we are in the architecture of the entity. my $arch_entity = $2; # match instance_name : entity if (/^\s*(\w+)\s*:\s*(\w+)$/) { print STDOUT "$1\t$2\t$arch_entity\n"; # find the entity and add the deps to it foreach my $ent (@entities) { if ($$ent{'name'} eq $arch_entity) { $$ent{'deps'}{$2}++; } } } } } close VHD; } foreach my $ent (@entities) { print "$$ent{'fname'}\t$$ent{'name'}\n"; foreach my $dep (keys %{ $$ent{'deps'} } ) { print "DEP: $dep $$ent{'deps'}{$dep} "; print "\n"; } }
However when I run the script only the last entity is printed from the last foreach loop. The problem seems to be that the %1 hash is overwritten by each successive match or something like that. I'm not sure. I thought what I did was ok output :
/proj/dice/external/adelante/24July2002/PowerBteFPGA/PBTE_FPGA/ref/coo +lrisc/status_816.vhd status_816 DEP: latchs_reg 34 DEP: pc_stack_816 11 DEP: latchr 367 DEP: latchr_reg 426 DEP: cr816lu 10 /proj/dice/external/adelante/24July2002/PowerBteFPGA/PBTE_FPGA/ref/coo +lrisc/status_816.vhd status_816 DEP: latchs_reg 34 DEP: pc_stack_816 11 DEP: latchr 367 DEP: latchr_reg 426 DEP: cr816lu 10 etc....

In reply to refs and hashes by diarmuid

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.