create output files with timestamp
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 8 Jul 2023 06:38:48 +0000 (08:38 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 8 Jul 2023 06:38:48 +0000 (08:38 +0200)
p.pl

diff --git a/p.pl b/p.pl
index 3b03016..9940b2c 100755 (executable)
--- a/p.pl
+++ b/p.pl
@@ -4,6 +4,7 @@ use strict;
 use autodie;
 use Data::Dump qw(dump);
 use Text::Unaccent;
+use POSIX qw(strftime);
 
 my $filename = 'Intervali_Openface_novi_rad_Boris_export.txt';
 
@@ -59,8 +60,11 @@ sub glob_id {
        }
 }
 
-my $nr = scalar(glob('out.*'));
-open(my $skipped_input, '>',"skip.input");
+my $today = strftime("%Y-%m-%dT%H:%M:%S ", localtime(time()));
+warn "# today $today";
+open(my $skipped_input, '>',"skip.$today");
+open(my $out_fh, '>', "out.$today");
+my @out_header;
 
 while(<$fh>) {
        chomp;
@@ -136,6 +140,15 @@ while(<$fh>) {
                        $h2nr = col2nr @h2;
                        $tell2 = tell($fh2);
                        warn "# h2nr ",dump( $h2nr ) if $debug;
+                       if ( ! @out_header ) {
+                               push @out_header, @cols;
+                               push @out_header, map { $h2[$_] }
+                                       ( $h2nr->{'AU01_r'} .. $h2nr->{'AU45_r'} );
+                               push @out_header, map { $h2[$_] }
+                                       ( $h2nr->{'AU01_c'} .. $h2nr->{'AU45_c'} );
+                               warn "# out_header ",dump( \@out_header );
+                               print $out_fh join("\t", @out_header),"\n";
+                       }
                        next;
                }
 
@@ -185,7 +198,7 @@ while(<$fh>) {
                        push @add_cols, map { $sum[$_] / $count } ( $h2nr->{'AU01_r'} .. $h2nr->{'AU45_r'} );
                        push @add_cols, map { $sum[$_] }          ( $h2nr->{'AU01_c'} .. $h2nr->{'AU45_c'} );
                        warn "# add_cols = ",dump( \@add_cols ) if $debug;
-                       print join("\t", @v, @add_cols ), "\n";
+                       print $out_fh join("\t", @v, @add_cols ), "\n";
 
                        @sum = ();
                        $count = 0;