Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to file bug

Status
Not open for further replies.

EchoCola

Programmer
Apr 13, 2004
48
US
This is the error i get:
Undefined subroutine &main::OUTFILE called at C:\PerlStuff\prog1.pl line 180, <INFILE2> line 1.

Any ideas?


Code:
open (INFILE1, "merge1.txt") ||
        die ("Cannot open input file merge1\n");
        
open (INFILE2, "merge2.txt") ||
        die ("Cannot open input file merge2\n");
        
open (OUTFILE,">outfile.txt") ||
	die ("Cannot open output file\n");

$line1 = <INFILE1>;
$line2 = <INFILE2>;
while ($line1 ne "" || $line2 ne "") {
       
        if ($line1 ne "") {
                print OUTFILE($line1);
                $line1 = <INFILE1>;
        }
        if ($line2 ne "") {
                print OUTFILE($line2);
                $line2 = <INFILE2>;
        }
}
 
Yeah your making it look like a subroutine. Try this:

Code:
        if ($line1 ne "") {
                print OUTFILE $line1;
                $line1 = <INFILE1>;
        }
        if ($line2 ne "") {
                print OUTFILE $line2;
                $line2 = <INFILE2>;
        }
Also, I would give your INFILE handlers an explicit resd from:

Code:
open (INFILE1, "< merge1.txt") ||
        die ("Cannot open input file merge1\n");
        
open (INFILE2, "< merge2.txt") ||
        die ("Cannot open input file merge2\n");


___________________________________
[morse]--... ...--[/morse], Eric.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top