Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Using the map function

by 2teez (Priest)
on Jul 10, 2013 at 18:28 UTC ( #1043525=note: print w/replies, xml ) Need Help??

in reply to Using the map function

Hi cspctec,
For me, using HASH of ARRAYs, could easily get this done for you like so:

use warnings; use strict; use Data::Dumper; my %hash; while (<DATA>) { chomp; next if /^\s*$/; my $key = $1 if /\w+?\s+?(.+?)\s+/; push @{ $hash{$key} }, $_; } print Dumper \%hash; __DATA__ CPU Temp = 30 GFX Temp = 45 RAM Temp = 40 CPU Status = OK GFX Status = OK RAM Status = OK
... produces ...
$VAR1 = { 'Temp' => [ 'CPU Temp = 30 ', 'GFX Temp = 45 ', 'RAM Temp = 40 ' ], 'Status' => [ 'CPU Status = OK ', 'GFX Status = OK ', 'RAM Status = OK' ] };

For more info. Please see perldsc
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043525]
[haukex]: the first index is always 0 - $#array gives you the last index in @array
[sierpinski]: gotcha, thanks
[LanX]: length = last index +1
[Eily]: yes LanX, both Metz and Nancy have a train station, it's just not the for the TGV
[LanX]: but the one in Metz is pretty! ;-p

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2017-12-13 16:08 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (369 votes). Check out past polls.