See my reply here Re^2: Hashes not working as expected

Try this demo

#!perl use Data::Dumper; my %hash = ( a=>{} ); if ( !exists $hash{'a'}{'b'}{'c'} ){}; print Dumper \%hash;

The problem is with exists creating intermediate levels

 foreach my $signalNm (keys %{$lastKnownSigValHRef->{$vcdFile}->{$signalId}}) {
    ### here
    if(!exists $inTimeRangeSignalsH{$vcdFile}{$signalNm}{$signalId}) {
     $sigsNotInTimeRangeH{$vcdFile}{$signalNm}{$signalId} = $lastKnownSigValHRef->{$vcdFile}->{$signalId}->{$signalNm}->{$hierScope}->[0];
    }
  }

I think you can fix it like this

foreach my $signalNm (keys %{$lastKnownSigValHRef->{$vcdFile}->{$signalId}}) {

  if (exists $inTimeRangeSignalsH{$vcdFile}{$signalNm}) {
    if (exists $inTimeRangeSignalsH{$vcdFile}{$signalNm}{$signalId}) {
      next;
    }
  }
  $sigsNotInTimeRangeH{$vcdFile}{$signalNm}{$signalId} 
  = $lastKnownSigValHRef->{$vcdFile}{$signalId}{$signalNm}{$hierScope}[0];

}

Update : Rather than returning variables from your methods you can encapsulate them into the object. For example, replacing the return statement from parseData with

#return(\%lastKnownSigValH, \%scopesHierH, \%scopesH, \%timeRangeH, # \%timeIntervalBasedActivityH, $vcdFile, $timeUnits); $self->{lastKnownSigValH} = \%lastKnownSigValH; $self->{scopesHierH} = \%scopesHierH; $self->{scopesH} = \%scopesH; $self->{timeRangeH} = \%timeRangeH; $self->{timeIntervalBasedActivityH} = \%timeIntervalBasedActivityH; $self->{vcdFile} = $vcdFile; $self->{timeUnits} = $timeUnits;

would allow you to write more readable code like this

#!/usr/bin/perl use strict; use warnings; use diagnostics -verbose; my $vcdFile = $ARGV[0]; my $datObj = Datafile->new(); $datObj->collectSignals($vcdFile); package Datafile; sub new { my $class = shift; my $self = { inTimeRangeSignalsH => {}, sigsNotInTimeRangeH => {}, timeRng => {}, hierScope => {}, }; return bless $self, $class; } sub collectSignals { my $self = shift; my $vcdFileOrig = shift; $self->parseData($vcdFileOrig); if (exists $self->{timeRangeH}{$vcdFile}) { my $timeRng = $self->{timeRangeH}{$vcdFile}{'TIMERANGES'}[-1]; $self->{timeRng} = $timeRng; if (exists $self->{timeIntervalBasedActivityH}{$vcdFile}) { my $hr1 = $self->{timeIntervalBasedActivityH}{$vcdFile}; if (exists $hr1->{$timeRng}) { my $hr2 = $hr1->{$timeRng}; for my $sigId (keys %$hr2) { for my $sigName (keys %{$hr2->{$sigId}}) { for my $scopeNm (keys %{$hr2->{$sigId}{$sigName}}) { if ( ($scopeNm =~ /_TB/) && (exists $hr2->{$sigId}{$sigName}{$scopeNm}{'EXPANDE +DVAL'}) ) { $self->{hierScope} = $scopeNm; my $sigValue = $hr2->{$sigId}{$sigName}{$scopeNm}{'EX +PANDEDVAL'}[-1]; $self->{inTimeRangeSignalsH}{$vcdFile}{$sigName}{$sigI +d}{$timeRng}{$scopeNm} = $sigValue; } } } } } foreach my $signal (keys %{$self->{inTimeRangeSignalsH}{$vcdFile +}}) { print "Line 51 ::Dbg:: $signal $vcdFile\n"; } } } if (exists $self->{lastKnownSigValH}{$vcdFile}) { my $hr1 = $self->{lastKnownSigValH}{$vcdFile}; foreach my $signalId (keys %$hr1) { foreach my $signalNm (keys %{$hr1->{$signalId}}) { if (exists $self->{inTimeRangeSignalsH}{$vcdFile}{$signalNm}){ if (exists $self->{inTimeRangeSignalsH}{$vcdFile}{$signalNm} +{$signalId}){ next; } } #if(!exists $self->{inTimeRangeSignalsH}{$vcdFile}{$signalNm}{ +$signalId}) { $self->{sigsNotInTimeRangeH}{$vcdFile}{$signalNm}{$signalId} = $hr1->{$signalId}{$signalNm}{$self->{hierScope}}[0]; #} } } } my $hr = $self->{inTimeRangeSignalsH}; for my $vcdFile (keys %$hr) { for my $sig (keys %{$hr->{$vcdFile}}) { print "Line 75 ::Dbg:: $sig $vcdFile\n"; } } }

For debugging, it also allows you to dump all the data easily with

use Data::Dump 'pp';
pp $datObj;
poj

In reply to Re: Why are Hash keys different for the same hash? Confusing. by poj
in thread Why are Hash keys different for the same hash? Confusing. by Anonymous Monk

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.