Hi Rolf!
Your code works, but I would make 2 modifications.
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";
Yes eof test is much better!
My first impulse, at first glance was to write a read_circular subroutine. But this winds up being "messy":
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; }
Or some such formulation...
If we have to wait until the read() is undefined, then a "re-read" is necessary. The "eof" status happens right after the last valid line is read. So no "re-reading" is needed. A far superior solution++.

...not sure how efficient the implementation is...
I am quite sure that your code will run very well. I will point out again, that
++$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
Again, Nice Idea using eof test++.

In reply to Re^4: writing two files (different in length) to one output by Marshall
in thread writing two files (different in length) to one output by ic23oluk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.