You need to close $fh1 before re-opening the file “j.txt” for reading. Or, alternatively, open the file just once, for both writing and reading:
... open (my $fh1, "+>", $output1) or die "Cannot open file '$output1': $! +"; ... seek $fh1, 0, 0; while (<$fh1>) { ...
(But — why don’t you use strict; ??)
Update: To clarify: the problem arises because the filehandle FILE is positioned at EOF (end-of-file), so the first call to <FILE> returns undef and the body of the while loop is never entered. Calling close $fh1; before re-opening the file ensures that FILE is initially positioned at the beginning of the file rather than the end. Calling seek $fh1, 0, 0; achieves the same result without the overhead of re-opening the file.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: How can one input a textfile from desktop just created?
by Athanasius
in thread How can one input a textfile from desktop just created?
by supriyoch_2008
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |