Perldiscuss - Perl Newsgroups And Mailing Lists wrote:
>
> Hi,
Hello,
> I need to read from more than one file at a time and do some operation on
> the strings and join them together, and put into one output file.
>
> Here is the code. But I noticed the second file never get read. It must be
> sth very simple to overcome this. Can anyone give me a hint?
use warnings;
use strict;
> # Usage: perl jointfiles.pl infile1 infile2 outfile
> open (IN1, $ARGV[0]);
> open (IN2, $ARGV[1]);
> open (OUT, ">$ARGV[2]");
You should _ALWAYS_ verify that the files opened correctly.
open (IN1, $ARGV[0]) or die "Cannot open $ARGV[0]: $!";
open (IN2, $ARGV[1]) or die "Cannot open $ARGV[1]: $!";
open (OUT, ">$ARGV[2]") or die "Cannot open $ARGV[2]: $!";
> print "Input fileis : $ARGV[0], $ARGV[1]\n";
> print "Output file: $ARGV[2]\n";
>
> while(<IN1>)
> {
> chomp;
> $in1=$_;
> <IN2>;
You are reading from IN2 in a void context. In other words, you are not
assigning the line you read from IN2 to a variable. It only gets
assigned to $_ in a while expression like "while(<IN1>)" above.
$in2 = <IN2>;
> $in2=$_;
> printf OUT "$in1$in2\n";
> }
> close(IN1);
> close(IN2);
> close(OUT);
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]