Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Using the map function

by AnomalousMonk (Monsignor)
on Jul 11, 2013 at 00:34 UTC ( #1043603=note: print w/ replies, xml ) Need Help??


in reply to Using the map function

I really like 2teez hash approach, although I would do it a little differently. Also a couple of array-only approaches. All of these easily generalize to any number of output arrays/groups/whatever. Note that the approach based on List::MoreUtils::part leaves you with a sub-array 0 filled with delimiter dreck.

>perl -wMstrict -le "use List::MoreUtils qw(part); use Data::Dump; ;; my @ra = ( 'CPU Temp = 30', 'GFX Temp = 45', 'RAM Temp = 40', '', 'CPU Status = OK', 'GFX Status = OK', 'RAM Status = OK', ); ;; my $p = 1; my @parts = part { m{ \A \s* \z }xms ? ($p = 2, 0) : $p } @ra; dd \@parts; ;; my @pointer = \my (@ra_1, @ra_2); my $pp = 0; m{ \A \s* \z }xms ? $pp = 1 : push @{ $pointer[$pp] }, $_ for @ra; dd \@ra_1; dd \@ra_2; ;; my %hash; m{ \b (Temp|Status) \b }xms and push @{ $hash{$1} }, $_ for @ra; dd \%hash; " [ [""], ["CPU Temp = 30", "GFX Temp = 45", "RAM Temp = 40"], ["CPU Status = OK", "GFX Status = OK", "RAM Status = OK"], ] ["CPU Temp = 30", "GFX Temp = 45", "RAM Temp = 40"] ["CPU Status = OK", "GFX Status = OK", "RAM Status = OK"] { Status => ["CPU Status = OK", "GFX Status = OK", "RAM Status = OK"], Temp => ["CPU Temp = 30", "GFX Temp = 45", "RAM Temp = 40"], }


Comment on Re: Using the map function
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-07-28 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (190 votes), past polls