Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Using the map function

by frozenwithjoy (Curate)
on Jul 10, 2013 at 17:41 UTC ( #1043513=note: print w/ replies, xml ) Need Help??


in reply to Using the map function

Here is an approach that works and is easy to read:

#!/usr/bin/env perl use strict; use warnings; my @status = <DATA>; my @temp; for (@status) { last if /^\s*$/; push @temp, $_; } print @temp; __DATA__ CPU Temp = 30 GFX Temp = 45 RAM Temp = 40 CPU Status = OK GFX Status = OK RAM Status = OK

Output:

CPU Temp = 30 GFX Temp = 45 RAM Temp = 40

UPDATE: The following results in two arrays (one for temperature and one with status)

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my @data = <DATA>; my @status = @data; my @temperature; for (@data) { shift @status; last if /^\s*$/; push @temperature, $_; } say "Temperature:"; print @temperature; say "Status:"; print @status; __DATA__ CPU Temp = 30 GFX Temp = 45 RAM Temp = 40 CPU Status = OK GFX Status = OK RAM Status = OK

Output:

Temperature: CPU Temp = 30 GFX Temp = 45 RAM Temp = 40 Status: CPU Status = OK GFX Status = OK RAM Status = OK


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://1043513]
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: (6)
As of 2015-07-02 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls