Try this for your summing code:
no warnings qw/numeric uninitialized/;
$sum_of_used += (split /\s+/) while <DATA>;
Filesystem total used avail capacity Mounted
/vol/vol0/ 142606336KB 5274244KB 137332092KB 4% /vol/v
/vol/vol0/.snapshot 35651584KB 923524KB 34728060KB 3% /vol/vo
/vol/vobstore/ 734003200KB 6335232KB 727667968KB 1% /vol/
/vol/vobstore/.snapshot 183500800KB 260200KB 183240600KB 0% /
/vol/ccase/ 125829120KB 21814420KB 104014700KB 17% /vol/
/vol/ccase/.snapshot 31457280KB 90572KB 31366708KB 0% /vol/c
/vol/viewstore/ 943718400KB 6492604KB 937225796KB 1% /vol/
/vol/viewstore/.snapshot 235929600KB 137500KB 235792100KB 0%
/vol/viewstore_win/ 67108864KB 480KB 67108384KB 0% /vol/vi
/vol/viewstore_win/.snapshot 16777216KB 2372KB 16774844KB 0%
It can be so simple because Perl knows how to make a number out of "almost" numbers. In other words, Perl simply disregards the 'KB' which is attached to the number. Everything which does not contain numbers will become 0, such as the header line. A perfect example of Perlish "Do What I Mean".
Of course I had to switch of the "not numeric" and "not initialized" warnings, but that is OK if you know what you are doing.
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||