in reply to How can one input a textfile from desktop just created?
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can one input a textfile from desktop just created?
by supriyoch_2008 (Monk) on Mar 08, 2014 at 06:52 UTC | |
by Athanasius (Archbishop) on Mar 08, 2014 at 09:43 UTC | |
by Laurent_R (Canon) on Mar 08, 2014 at 17:03 UTC |