I'm writing a script to capture the number of pings sent and received on a per interface basis. The data is available in a text file - with one line for the ping send and another for each ping response. There could be multiple ping sends with successive increased timeouts if there is no ping response.
I'm using a hash to hold the values with the data structure as shown below:
%frq_node = (); # Each hash entry will have a key corresponding to an interface # Each value is an array of 2 elements; element 0 is a hash # with each hash key being the timeout value of a ping send # and the value being the number of pings for that hash # value. element 1 is the number of received pings # open file code here while (<FH>) { if (/sending ping/) { # Extract interface key from line into $key # Extract the timeout value in sending ping $to # Increment the hash value of the corresponding # timeout bucket for the interface ${$frq_node{$key}[0]}{$to}++; # Does not work } elsif (/recevied ping response) { # Increment # of received pings for interface $frq_node{$key}[1]++; # Works fine! } }
Any ideas on where i'm going wrong with "${$frq_node{$key}[0]}{$to}++; " ?
Thanks !

In reply to Anonymous hash with array by vasu

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.