It's not apparent what you are trying to do. Here's your code cleaned up with the syntax errors removed:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash=(); %hash=( ##keys between "" because of dots "M01.001" =>["M01.001"], "M01.001.111" =>["M01.001.111"], "M01.001.111.111" =>["M01.001.111.111"], "M01.002" =>["M01.002"], "M01.002.003" =>["M01.002.003"], ); print Dumper(%hash), "\n"; for my $k(sort keys %hash){ my $temp = reverse($k); $temp =~ s/^\d{3}\.?//; my $t= reverse ($temp); if (exists $hash{$t}){ $hash{$k}[1] += 1; } } print Dumper(%hash); __END__

As for the $hash{$k}[1] += 1; "not working", it is working. It might not be doing what you wanted, but it's doing what somebody would expect, which is to create a second element in the array $hash{$k}, and then add 1 to it, to produce the result 1. If you meant to add 1 to the string "M01.001", what exactly do you think that means? You can't add the integer 1 to a string. It doesn't make sense.


In reply to Re: Incrementing a hash of array value by beable
in thread Incrementing a hash of array value 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.