in reply to Re^3: writing two files (different in length) to one output
in thread writing two files (different in length) to one output
Yes eof test is much better!my $finished_1, $finished_2; # should be: my ($finished_1, $finished_2); # list context is needed for the "my" to apply to # both variables. chomp $line1, $line2; # the chomp() does not operate on $line2. # Again, list context is needed... # chomp ($line1, $line2); # but that requires a change in the print # # e.g., print "$line1 \t $line2\n"; # # Of course code could be just: # chomp $line1; #leave $line2 out of it! # My coding preference would be to be symmetrical, # i.e. # chomp ($line1, $line2); # and add the extra $line2 line ending back in # during the print. # # instead of: print "$line1 \t $line2"; # print "$line1 \t $line2\n";
Or some such formulation...sub read_circular { my $fh = shift; my $line; do { $line = <$fh>; seek ($fh,0,0) if !(defined $line); #restart from beginning }until (defined $line); return $line; }
...not sure how efficient the implementation is...I am quite sure that your code will run very well. I will point out again, that
Again, Nice Idea using eof test++.++$finished_1, seek ONE,0,0 if eof ONE; # this is the same as if ( eof ONE) { $finished_1++; #post or pre-increment the same seek ONE,0,0; } # the number of source code lines does not equate # directly into actual "code savings". The more # wordy "if" loop will code into very similar, if # not the exactly the same executing code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: writing two files (different in length) to one output
by LanX (Saint) on May 30, 2017 at 20:48 UTC | |
by Marshall (Canon) on May 30, 2017 at 22:31 UTC | |
by LanX (Saint) on May 30, 2017 at 22:56 UTC | |
by Marshall (Canon) on May 31, 2017 at 00:27 UTC | |
by hippo (Archbishop) on May 31, 2017 at 07:29 UTC | |
| |
by LanX (Saint) on May 31, 2017 at 00:39 UTC |