Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's some not so good looking perl code that does the job. Perhaps you can find it useful in some way. Quick hack, there are other ways of doing it (I feel that this code needs defending).</p> <pre><code>#!/usr/bin/perl -w # # $Id$ # use strict; use warnings; my @ITEMS; my $item; my $state = 0; open(FD, "&lt; data.txt") or die "Failed to open file."; while (my $line = &lt;FD&gt;) { $line =~ s/(\r|\n)//g; if ($line =~ /^===== Item (\d+)\/\d+/) { my $item_number = $1; if ($item) { # Just to make sure we don't have two lines that seems to be a headline in a row. # If we have an item but haven't set the title it means that there are two in a row that matches. die "Something seems to be wrong, better safe than sorry. Line $. : $line\n" if (not $item-&gt;{title}); # If we have a new item number add previuos item and create a new. if ($item_number != $item-&gt;{item_number}) { push(@ITEMS, $item); $item = {}; $item-&gt;{item_number} = $item_number; } } else { # First entry, don't have an item. $item = {}; # Create new item. $item-&gt;{item_number} = $item_number; } $state = 1; } elsif ($state == 1) { die "Data must start with a headline." if (not $item); # If we already have a title make sure it matches. if ($item-&gt;{title}) { if ($item-&gt;{title} ne $line) { die "Title doesn't match for item " . $item-&gt;{item_number} . ", line $. : $line\n"; } } else { $item-&gt;{title} = $line; } $state++; } elsif (($state == 2) &amp;&amp; ($line =~ /^Info:/)) { # Just make sure that for state 2 we have a line that match Info. $state++; } elsif (($state == 3) &amp;&amp; ($line =~ /^Test finished\. Result ([^.]+)\. Time \d+ secunds{0,1}\.$/)) { $item-&gt;{status} = $1; $state++; } elsif (($state == 4) &amp;&amp; ($line =~ /^Stats:/)) { $state++; # After Stats we must have a new item or we should fail. } else { die "Invalid data, line $.: $line\n"; } } # Need to take care of the last item too. push(@ITEMS, $item) if ($item); close FD; # Loop our items and print the info we stored. for $item (@ITEMS) { print $item-&gt;{item_number} . " (" . $item-&gt;{status} . ") " . $item-&gt;{title} . "\n"; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload