Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Counting devices types, device sizes and number of devices.

by Marshall (Prior)
on Jan 06, 2012 at 17:26 UTC ( #946631=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Counting devices types, device sizes and number of devices.
in thread Counting devices types, device sizes and number of devices.

Another tip for you...With Perl, you can specify indicies from either side of an array or list. Some of your data lines have 8 some 9 things. So to get the 6th thing and the last thing, do it like this.. Main point is that by using negative index, you can get the last thing even if number of things varies. I think your actual data is tab separated? if so, then adjust accordingly.

while (<DATA>) { my ($desc,$MB) = (split)[5,-1]; print "$desc $MB\n"; } =prints 2-Way 3 2-Way 3 2-Way 3 RAID-5 8632 RAID-5 8632 RAID-5 34526 2-Way 34526 2-Way 34526 2-Way 69052 RAID-5 34526 RAID-5 34526 RAID-5 69052 RAID-5 69052 BCV+R5 34526 BCV+R5 34526
The index of -1 means "last item", -2 would mean next to last one, etc.


Comment on Re^3: Counting devices types, device sizes and number of devices.
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://946631]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-10-02 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (56 votes), past polls