in reply to Perl prints only one line when directed to a file but print to a screen works
foreach my $listDevices ($device_list->result()) { ... open OVERWRITE, ">overwrite.txt" or die $! ... close OVERWRITE; ... }
Do you see what is happening?
You have even called the filehandle "OVERWRITE".
The file gets overwritten every time the loop and if directive come by the call to open
Solution: place both the open and close outside of the foreach loop.
open goes first, then the loop, and when that's done, close the filehandle.
Cheers, Sören
(hooked on the Perl Programming language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl prints only one line when directed to a file but print to a screen works
by vlad3848 (Acolyte) on Jun 30, 2013 at 17:52 UTC |