From 8371d30cba7e8f50b3fe39808d4039444a375f5e Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Sun, 22 Sep 2019 20:36:11 +0200
Subject: [PATCH] allow output to stdout

---
 modules/util/Util/Matrix.pm | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/modules/util/Util/Matrix.pm b/modules/util/Util/Matrix.pm
index 98ed31b..3b5d800 100644
--- a/modules/util/Util/Matrix.pm
+++ b/modules/util/Util/Matrix.pm
@@ -204,14 +204,25 @@ sub save_as_csv
   my $eol= shift || "\n";
   my $utf8= shift || 0;
 
-  unless (open (FO, '>', $fnm))
+  my $fo_open= 0;
+  if ($fnm eq '-')
   {
-    print "ATTN: cant save as csv [$fnm]\n";
-    return undef;
+    *FO= *STDOUT;
   }
+  else
+  {
+    unless (open (FO, '>', $fnm))
+    {
+      print STDERR "ATTN: cant save as csv [$fnm]\n";
+      return undef;
+    }
+
+    $fo_open= 1;
+  }
+
   if ($utf8)
   {
-    print "ATTN: binmode :utf8 [$fnm]\n";
+    print STDERR "ATTN: binmode :utf8 [$fnm]\n";
     binmode (FO, ':utf8');
   }
 
@@ -222,7 +233,7 @@ sub save_as_csv
     print FO join ($csv_sep, map { $col_delimiter . $_ . $col_delimiter } @$row), $eol;
     $lines++;
   }
-  close (FO);
+  close (FO) if ($fo_open);
   $lines;
 }
 
-- 
GitLab