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

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.

Replies are listed 'Best First'.
Re^3: Why are Hash keys different for the same hash? Confusing. (VCD)
by 1nickt (Canon) on Feb 28, 2016 at 12:27 UTC

    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.