Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: help with data structure to use and how to implement it

by 2teez (Vicar)
on Sep 25, 2014 at 04:29 UTC ( [id://1101893]=note: print w/replies, xml ) Need Help??


in reply to help with data structure to use and how to implement it

Hi,
Of course you can use hash like so:

use warnings; use strict; use Data::Dumper; my %data; while(<DATA>){ my ($server_name,$fault) = (split/:|\s+/,$_)[0,2]; $data{$server_name}{$fault}++; } print Dumper \%data; __DATA__ Server1:london:network_interface Server1:london:diskspace Server1:london:diskpace Server1:london:kernel Server2:paris:diskspace Server3:new_york:Kernel Server3:new_york:diskspace Server3:new_york:diskspace Server3:new_york:kernel
Output:
$VAR1 = { 'Server3' => { 'kernel' => 1, 'diskspace' => 2, 'Kernel' => 1 }, 'Server1' => { 'kernel' => 1, 'diskpace' => 1, 'diskspace' => 1, 'network_interface' => 1 }, 'Server2' => { 'diskspace' => 1 } };
The rest will then be just to print out! Over to you.

Update: Please note that 'kernel' is not the same with 'Kernel', neither is diskpace same with diskspace

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found