Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would switch to reading two lines, rather than one:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use autodie; print "X,Y,Val\n"; for my $filename (@ARGV) { open my $log, "&lt;", $filename; while (my $coord_line = &lt;$log&gt;) { my ($x, $y) = $coord_line =~ /\((-?[0-9]+),(-?[0-9])\)/ or die "bad coored line"; my $results_line = &lt;$log&gt;; my ($val,$err) = $results_line =~ /^Results.*\((.*),(.*)\)$/ or die "bad results line"; print "$x,$y,$val:$err\n"; } } </code></pre> <p>One of the benefits of this approach is that your variables are now properly scoped. A simpler version of this program is:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use ARGV::readonly; #prevent files like "|ls" from breaking us print "X,Y,Val\n"; while (&lt;&gt;) { my ($x, $y) = /\((-?[0-9]+),(-?[0-9]+)\)/ or die "bad coored line"; my ($val,$err) = &lt;&gt; =~ /^Results.*\((.*),(.*)\)$/ or die "bad results line"; print "$x,$y,$val:$err\n"; } </code></pre> <p>Another variant that takes into account the possibility of lines between the two lines we care about. It assumes the first coordinate pair is the right one:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use ARGV::readonly; #prevent files like "|ls" from breaking us print "X,Y,Val\n"; while (&lt;&gt;) { next unless my ($x, $y) = /\((-?[0-9]+),(-?[0-9]+)\)/; my ($val, $err); while (&lt;&gt;) { last if ($val, $err) = /^Results.*\((.*),(.*)\)$/; } die "bad format" unless defined $val; print "$x,$y,$val:$err\n"; } </code></pre> <p>And this one handles the case where you want the last coordinate line:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use ARGV::readonly; #prevent files like "|ls" from breaking us print "X,Y,Val\n"; my ($x, $y); while (&lt;&gt;) { ($x, $y) = ($1, $2) if /\((-?[0-9]+),(-?[0-9]+)\)/; next unless my ($val, $err) = /^Results.*\((.*),(.*)\)$/; print "$x,$y,$val:$err\n"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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