in reply to Re: Merging files, 1 line for every 10
in thread Merging files, 1 line for every 10

I'd recommend a simpler code:
open my $in_fh1, '<', $in_file1; open my $in_fh2, '<', $in_file2; open my $out_fh, '>', $out_file; while (defined(my $line1 = <$in_fh1>)) { print {$out_fh} $line1; unless ($. % 10) { my $line = <$in_fh2>; print {$out_fh} $line; } }

Replies are listed 'Best First'.
Re^3: Merging files, 1 line for every 10
by Kc12349 (Monk) on Sep 07, 2011 at 22:13 UTC

    The use of $. does make things more simple. I'll have to take note of that for similar situations in the future. What is the benefit of the added defined call?

      It deals with the edge case where $line gets a value that is false before the actual end of file.

      True laziness is hard work