I'd use a regex to pull out the fields you are interested in then use split to chop em up. With a little cunning you can leverage map and a for (as a statement modifier) to get everything done in a fairly compact, but lucid way. Consider:

use warnings; use strict; my $data = <<'DATA'; Summary 51.58.214.48/dw109998bsw45 -> (1*Cisco_Power_Supply) (1*Cisco_ +CPU_Unit) (7*IETF_IF) (1*Cisco_Fan_Unit) (1*1213_Device) (2*Cisco_Mem +ory_Pool) Summary 51.58.220.21/dw108432bsw25 -> (6*Cisco_Power_Supply +) (1*Cisco_CPU_Unit) (333*IETF_IF) (6*Cisco_Fan_Unit) (1*1213_Device) + (2*Cisco_Memory_Pool)DATA DATA my %totals; $totals{$_->[1]} += $_->[0] for map {[split '\*']} $data =~ /\(([^)]*) +\)/g; print "$_: $totals{$_}\n" for sort keys %totals;

Prints:

1213_Device: 2 Cisco_CPU_Unit: 2 Cisco_Fan_Unit: 7 Cisco_Memory_Pool: 4 Cisco_Power_Supply: 7 IETF_IF: 340

Note the trick of putting the split inside a [] pair to create a two element array for each item the regex generates. The chunk to the left of the for builds a hash of totals keyed by item type.


Perl is environmentally friendly - it saves trees

In reply to Re: split snafus by GrandFather
in thread split snafus by manav_gupta

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.