Here are two versions: the first one intermixes all the lines from
the files, the second allows you to decide on a limit of how many
lines to read from the files (as per your followup specifications):
#!/usr/bin/perl -w
use strict;
use IO::File;
my @files = qw/file1 file2 file3/;
my @fhs = map{IO::File->new($_)||die "$_: $!"} @files;
print while $_ = join '', map{scalar <$_>||''} @fhs;
__END__
#!/usr/bin/perl -w
use strict;
use IO::File;
my $limit = 2000;
my @files = qw/file1 file2 file3/;
my @fhs = map{IO::File->new($_)||die "$_: $!"} @files;
for(1 .. $limit) {
$_ = join '', map{scalar <$_>||''} @fhs or last;
print;
}
__END__
Both assume that you'll just redirect output to the new file, but
you can open() an output filehandle and print to it if you wish.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|