in reply to Re^2: blocks and using braces around filehandles with print
in thread blocks and using braces around filehandles with print
fh.pl syntax OKdie "Ouch. $!" unless open my $fh, '>', 'foo.txt'; print {$fh;} "hi!\n"; close $fh;
Note that if you're storing FILEHANDLEs in an array, or if you're using any other expression more complex than a scalar variable to retrieve it, you will have to use a block returning the filehandle value instead: print { $files[$i] } "stuff\n"; print { $OK ? STDOUT : STDERR } "stuff\n";
|
|---|