Dear monks , can you throw some light on below issue as i am unable to figure out why my hash structure is messing up while referencing array as the key value. I had done the same is past for another script and conceptually it works but somehow in this case not sure whats wrong. My code is below. I have added all but just the main logic where hash is generated

my %parCode = ( 0 => "partition-1", 1 => "partition-2", 2 => "partition-3", 3 => "partition-4" ); while (my $in_line = <INFILE>) { @time_arr = (); chomp($in_line); if ($in_line =~ /Registered listener on template/){ #print "$in_line\n"; @row = split('\s',$in_line); ($r{time},$r{partition}) = ($row[0],$row[-1]); $r{partitionName} = $parCode{$r{partition}}; #print Dumper(\@row); #print Dumper(\%r); if (exists $parMap_ha{$r{partitionName}}){ #print " >> ### Time event detected - $r{partition} - $pa +rCode{$r{partition}}\n"; #print Dumper(\%parMap_ha); push(@time_arr,@{$parMap_ha{$r{partition +Name}}},$r{time}); #print Dumper(\@time_arr); $parMap_ha{$r{partitionName}} =\@time_ +arr; #print " << ### post modification \n"; #print Dumper(\%parMap_ha); } else{ $parMap_ha{$r{partitionName}} =[$r{tim +e}]; #print " >> *** 1st event detected - $r{partition} - $r{ +partitionName}\n"; #print Dumper(\%parMap_ha); } } }

Below is the hash dump with infile data where you can see that this works for the 1st few iterations and later the hash messes up

## ARRAY @row ### $VAR1 = [ '20160515-20:46:58.945+0900', 'server', 'id:', '2' ]; ## HASH %r ### $VAR1 = { 'time' => '20160515-20:46:58.945+0900', 'partitionName' => 'partition-3', 'partition' => '2' }; >> *** 1st event detected - 2 - partition-3 ## HASH %parMap_ha ### $VAR1 = { 'partition-3' => [ '20160515-20:46:58.945+0900' ] }; $VAR1 = [ '20160515-20:46:59.138+0900', 'server', 'id:', '3' ]; $VAR1 = { 'time' => '20160515-20:46:59.138+0900', 'partitionName' => 'partition-4', 'partition' => '3' }; >> *** 1st event detected - 3 - partition-4 $VAR1 = { 'partition-4' => [ '20160515-20:46:59.138+0900' ], 'partition-3' => [ '20160515-20:46:58.945+0900' ] }; $VAR1 = [ '20160515-20:46:59.145+0900', 'id:', '0' ]; $VAR1 = { 'time' => '20160515-20:46:59.145+0900', 'partitionName' => 'partition-1', 'partition' => '0' }; >> *** 1st event detected - 0 - partition-1 $VAR1 = { 'partition-4' => [ '20160515-20:46:59.138+0900' ], 'partition-1' => [ '20160515-20:46:59.145+0900' ], 'partition-3' => [ '20160515-20:46:58.945+0900' ] }; $VAR1 = [ '20160515-20:46:59.153+0900', 'id:', '1' ]; $VAR1 = { 'time' => '20160515-20:46:59.153+0900', 'partitionName' => 'partition-2', 'partition' => '1' }; >> *** 1st event detected - 1 - partition-2 $VAR1 = { 'partition-4' => [ '20160515-20:46:59.138+0900' ], 'partition-2' => [ '20160515-20:46:59.153+0900' ], 'partition-1' => [ '20160515-20:46:59.145+0900' ], 'partition-3' => [ '20160515-20:46:58.945+0900' ] }; $VAR1 = [ '20160516-01:04:40.210+0900', 'id:', '3' ]; $VAR1 = { 'time' => '20160516-01:04:40.210+0900', 'partitionName' => 'partition-4', 'partition' => '3' }; >> ### Time event detected - 3 - partition-4 ## HASH %parMap_ha ### $VAR1 = { 'partition-4' => [ '20160515-20:46:59.138+0900' ], 'partition-2' => [ '20160515-20:46:59.153+0900' ], 'partition-1' => [ '20160515-20:46:59.145+0900' ], 'partition-3' => [ '20160515-20:46:58.945+0900' ] }; ## ARRAY @time_arr ### $VAR1 = [ '20160515-20:46:59.138+0900', '20160516-01:04:40.210+0900' ]; << ### post modification ## HASH %parMap_ha ### $VAR1 = { 'partition-4' => [ '20160515-20:46:59.138+0900', '20160516-01:04:40.210+0900' ], 'partition-2' => [ '20160515-20:46:59.153+0900' ], 'partition-1' => [ '20160515-20:46:59.145+0900' ], 'partition-3' => [ '20160515-20:46:58.945+0900' ] }; $VAR1 = [ '20160516-01:04:57.643+0900', 'id:', '1' ]; $VAR1 = { 'time' => '20160516-01:04:57.643+0900', 'partitionName' => 'partition-2', 'partition' => '1' }; >> ### Time event detected - 1 - partition-2 ## HASH %parMap_ha ### ## LOOK at the hash value as its starting to messup ## $VAR1 = { 'partition-4' => [], 'partition-2' => [ '20160515-20:46:59.153+0900' ], 'partition-1' => [ '20160515-20:46:59.145+0900' ], 'partition-3' => [ '20160515-20:46:58.945+0900' ] }; $VAR1 = [ '20160515-20:46:59.153+0900', '20160516-01:04:57.643+0900' ]; << ### post modification ## LOOK at the hash value (line-2) as its starting to messup ## $VAR1 = { 'partition-4' => [ '20160515-20:46:59.153+0900', '20160516-01:04:57.643+0900' ], 'partition-2' => $VAR1->{'partition-4'}, 'partition-1' => [ '20160515-20:46:59.145+0900' ], 'partition-3' => [ '20160515-20:46:58.945+0900' ] };

As always thanks in advance!


In reply to Problem is assigning array as hash value by udvk009

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.