[Israel.pm] Array of file handles

Shlomi Fish shlomif at iglu.org.il
Mon Dec 13 06:16:08 PST 2004

On Monday 13 December 2004 15:56, David Baird wrote:
> Can anyone explain why the following isn't valid:
> my $files = 8;
> my (@fharray);
> (my $basename = $0) =~ s/\.[^.]*$//;
> for my $h (0 .. ($files - 1)) {
>    unlink "${basename}_$h.mif";
>    open $fharray[$h], ">${basename}_$h.txt";
>    print $fharray[$h] "file $h\n";

The problem is in this line. You need to write it as:

print {$fharray[$h]} "file $h\n";

I guess Perl frowns upon the print statement's filehandle being anything other 
than a simple variable if the braces are to be omitted.


	Shlomi Fish

Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://www.shlomifish.org/

Knuth is not God! It took him two days to build the Roman Empire.

More information about the Perl mailing list