strip trailing carriage returns
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Sep 2019 20:08:13 +0000 (22:08 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Sep 2019 21:56:49 +0000 (23:56 +0200)
Support CRLF line termination regardless of system record separator,
preventing mangled output due to column returns before appended graphs.
Besides Windows files, \r is also added by unbuffer -p for some reason.

graph

diff --git a/graph b/graph
index eaafb764d387a5f65514ed3fcb017e8763e62840..e76ec645492b138a49ddfb11a52f1adf2e4b2088 100755 (executable)
--- a/graph
+++ b/graph
@@ -39,7 +39,7 @@ $SIG{INT} = 'IGNORE';  # continue after assumed eof
 
 my (@lines, @values);
 while (readline) {
-       chomp;
+       s/\r?\n\z//;
        s/^\h*// unless $opt{unmodified};
        push @values, s/^ ( \h* -? [0-9]* \.? [0-9]+ |)//x && $1;
        if (defined $opt{trim}) {