Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Why are Hash keys different for the same hash? Confusing. (VCD)

by toolic (Bishop)
on Feb 27, 2016 at 21:11 UTC ( [id://1156333]=note: print w/replies, xml ) Need Help??


in reply to Why are Hash keys different for the same hash? Confusing.

tl;dr, but... for parsing a VCD file, don't reinvent this wheel if you don't have to: Verilog::VCD. For example, the following code parses your VCD file and shows all signal names, times and values:
use warnings FATAL => 'all'; use strict; use Verilog::VCD qw(parse_vcd); my $file = shift; my $vcd = parse_vcd($file); for my $code (keys %{ $vcd }) { my $name = "$vcd->{$code}{nets}[0]{hier}.$vcd->{$code}{nets}[0]{n +ame}"; my $times = @{ $vcd->{$code}{tv} }; for my $aref (@{ $vcd->{$code}{tv} }) { print "$name @{ $aref }\n"; } } __END__ JUNKSIGNALS_TB.RIGHT 0 1 JUNKSIGNALS_TB.RIGHT 10 0 JUNKSIGNALS_TB.SERIAL 0 1 JUNKSIGNALS_TB.I2 0 0 JUNKSIGNALS_TB.DUTJNKCELL.lnx5_out 0 0 JUNKSIGNALS_TB.DUTJNKCELL.lnx3_out 0 0 JUNKSIGNALS_TB.DUTJNKCELL.lnx4_out 0 1 JUNKSIGNALS_TB.I1 0 0 JUNKSIGNALS_TB.DUTJNKCELL.lnx2_out 0 1 JUNKSIGNALS_TB.DUTJNKCELL.lnx2_out 10 0 JUNKSIGNALS_TB.ZEN 0 1 JUNKSIGNALS_TB.ZEN 10 0 JUNKSIGNALS_TB.DUTJNKCELL.lnx0_out 0 0 JUNKSIGNALS_TB.DUTJNKCELL.lnx0_out 10 1 JUNKSIGNALS_TB.DUTJNKCELL.lnx1_out 0 0 JUNKSIGNALS_TB.DUTJNKCELL.lnx1_out 10 1 JUNKSIGNALS_TB.I0 0 0 JUNKSIGNALS_TB.I0 10 1

If you can explain in words what you are trying to accomplish, I can try to help (I speak Verilog). Also keep in mind that hashes are un-ordered in Perl, and generally, you want to sort the keys.

UPDATE: A few years ago, some translated this Perl code to Python: https://pypi.python.org/pypi/Verilog_VCD

  • Comment on Re: Why are Hash keys different for the same hash? Confusing. (VCD)
  • Download Code

Replies are listed 'Best First'.
Re^2: Why are Hash keys different for the same hash? Confusing. (VCD)
by Anonymous Monk on Feb 27, 2016 at 21:41 UTC

    Hi toolic, that is great you speak Verilog. May be, I can seek some help with my hash described below from the original code :)

    Here is a very basic question I have. Perhaps, I did not ask the core of my question earlier, correctly and got lost in the details:

    In lines 47 through 49, I have the following code, where I am printing keys:

    47 foreach my $signal (keys %{$inTimeRangeSignalsH{$vcdFile}}) { 48 print "Line 48 ::Dbg:: $signal $vcdFile\n"; 49 }

    Further down in my code in lines 61 through 65, I am again printing the same keys and expecting that I get the same keys are the result (order of results is not important).

    But unfortunately, that expectation does not seem to be true.

    Why are the keys from the same hash different, when printed using lines 48 through 49 and lines 61 through 65?

    61 foreach my $vcdFile (keys %inTimeRangeSignalsH) { 62 foreach my $sig (keys %{$inTimeRangeSignalsH{$vcdFile}}) { 63 print "Line 63 ::Dbg:: $sig $vcdFile\n"; 64 } 65 }

    Any insights/corrections will be a great help.

      Your code is very difficult to read. Using standard four spaces for indentation would help.

      Each of those debug loops happens within a different conditional clause, so (without deciphering the function of your program) it would not be surprising if the data within the hash were different in each case.

      As someone else mentioned, you can use sort to print out your hash in the same order each time; makes it easier to see what's going on.

      You can also use Data::Dumper to save yourself a lot of boilerplate debugging code.

      (Data::Dumper is part of core Perl, so your overlords should be okay with it. On the other hand, I would seriously reconsider my participation if my boss told me to do a project in Perl without CPAN -- that's just silly.)

      The way forward always starts with a minimal test.
Re^2: Why are Hash keys different for the same hash? Confusing. (VCD)
by Anonymous Monk on Feb 27, 2016 at 21:22 UTC
    Unfortunately, we cannot use outside modules as we have to write everything from scratch (customer gets what he wants:) )
      Sure you can. It is pure Perl code. Just copy and paste it from the CPAN website, just as you would copy and paste whatever code someone posts here.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1156333]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found