Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Storing system grep's output to an array in perl

by arnaud99 (Beadle)
on Mar 07, 2013 at 11:52 UTC ( #1022216=note: print w/ replies, xml ) Need Help??


in reply to Storing system grep's output to an array in perl

Hi

A similar approach to the one above

use strict; use warnings; my @all_times; while (my $line = <DATA>) { if ($line =~ /^top - /) { chomp $line; my ($top, $dash, $time, @rest) = split /\s+/, $line; push @all_times, $time; } } for (@all_times) { print $_, "\n"; } __DATA__ top - 00:35:18 up... blah blah blah ..... top - 00:35:15 up... fwertwe blah blah blah ..... blah blah blah ..... blah blah blah ..... blah blah blah ..... blah blah blah ..... top - 00:35:20 up... blah blah blah ..... top - 00:35:22 up... blah blah blah ..... top - 00:35:30 up... blah blah blah .....

Output is:

00:35:18 00:35:15 00:35:20 00:35:22 00:35:30

Arnaud


Comment on Re: Storing system grep's output to an array in perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2015-07-28 04:25 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 (252 votes), past polls