in reply to Output To File with Array help
One of your problems is that you're attempting to print to a scalar value containing a string instead of a scalar value containing a file handle.
The first argument to print should be a file handle, not a string.
If you wanted to loop over an array of file handles and print the same output to each, you could try this:
use strict; my $scalar = "We Be Killing Zombies Tonite"; my @array = (">poo.txt", ">moo.txt", ">doo.txt", ">goo.txt"); my @filehandle; open($filehandle[0], $array[0]); open($filehandle[1], $array[1]); open($filehandle[2], $array[2]); open($filehandle[3], $array[3]); for my $fh (@filehandle) { print $fh "$scalar"; }
|
|---|