I have a list of IP Addresses and the amount of data that they have transfered over a period of time, it is in the form:
10.0.0.1 555555 10.2.1.6 444444 10.6.2.8 333333 10.2.1.2 222222 etc...
I am performing some actions on these IP's but ideally I would like to do it by subnet. All the IP Addresses on the network belong to a /29 subnet. I am using NetAddr::IP to then get the network address that corresponds to each individual IP. The list could look like this
10.0.0.0/29 10.0.0.1 555555 10.2.1.0/29 10.2.1.6 444444 10.6.2.0/29 10.6.2.8 333333 10.2.1.0/29 10.2.1.2 222222 etc...
I now want to group together all the lines that have the same network address and add up the bytes transfered. This in theory would like something like:
10.2.1.0/29 666666 10.0.0.0/29 555555 10.6.2.0/29 333333
I then need to run these through some more processes that I have working on the individual IP Addresses at the moment. The problem is that there are a very large amount of IP's and subnets, and they can change over every measurement period as can the data transfered.

At the moment I am trying to use arrays and foreach loops etc.. to try and get this working.

Any help as I struggle on with this would be appreciated.


In reply to Sorting IP Subnets together by strat.minger

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.