Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: i am trying to parse set of data from a file, sorting that data and writing to a new file

by choroba (Archbishop)
on Feb 04, 2020 at 12:28 UTC ( #11112360=note: print w/replies, xml ) Need Help??


in reply to i am trying to parse set of data from a file, sorting that data and writing to a new file

Store the durations in a hash keyed by the ids.

#!/usr/bin/perl use strict; use warnings; use List::Util qw{ first }; my %duration; my $id; while (<DATA>) { chomp; $id = $1 if /Launching (\S+)/; if (my ($days, $hours, $minutes, $seconds) = /Run Duration: (.*)d +(.*):(.*):(.*)/) { $duration{$id} = [$days, $hours, $minutes, $seconds]; } } for my $id (sort { my $d = first { $duration{$a}[$_] <=> $duration{$b}[$_ +] } 0 .. 3; $duration{$a}[$d] <=> $duration{$b}[$d] } keys %duration ) { print "$id\t"; print $duration{$id}[0], 'd'; print join ':', @{ $duration{$id} }[1, 2, 3]; print "\n"; } __DATA__ Launching series_eleven (started Sat Jan 11 7:31:47 PST 2020) SERIES RESULT (series_eleven) : Pass: 2/0/0 series_eleven (finished Sat Jan 11 7:31:58 PST 2020) series_eleven Run Duration: 0d 00:00:11 Launching series_twenty (started Sat Jan 11 7:31:47 PST 2020) SERIES RESULT (series_twenty) : Pass: 2/0/0 series_twenty (finished Sat Jan 11 7:31:58 PST 2020) series_twenty Run Duration: 0d 00:00:20 Launching series_minute (started Sat Jan 11 7:31:47 PST 2020) SERIES RESULT (series_minute) : Pass: 2/0/0 series_minute (finished Sat Jan 11 7:31:58 PST 2020) series_minute Run Duration: 0d 00:01:00 Launching series_hour (started Sat Jan 11 7:31:47 PST 2020) SERIES RESULT (series_hour) : Pass: 2/0/0 series_hour (finished Sat Jan 11 7:31:58 PST 2020) series_hour Run Duration: 0d 01:00:00 Launching series_day (started Sat Jan 11 7:31:47 PST 2020) SERIES RESULT (series_day) : Pass: 2/0/0 series_day (finished Sat Jan 11 7:31:58 PST 2020) series_day Run Duration: 1d 00:00:00 Launching series_week (started Sat Jan 11 7:31:47 PST 2020) SERIES RESULT (series_week) : Pass: 2/0/0 series_week (finished Sat Jan 11 7:31:58 PST 2020) series_week Run Duration: 7d 00:00:00
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
  • Comment on Re: i am trying to parse set of data from a file, sorting that data and writing to a new file
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-05-29 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (166 votes). Check out past polls.

    Notices?