Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Using the map function

by frozenwithjoy (Priest)
on Jul 10, 2013 at 17:41 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-24 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found