in reply to Re: Re: 'strict refs' + 'strict sub' = suck.
in thread 'strict refs' + 'strict sub' = suck.
However the above code is not valid in version of Perl prior to 5.6.0, which I am still using on some of the production boxes. However the following will work on Perl prior to 5.6.0.open my $fh, ">output.txt" or die "Can't create output: $!"; print {$fh} "Hello world!\n"; close $fh; # if don't close, then it will be closed # automatically when $fh is out of scope.
My preference of IO::File over open is on the Perl version compatibility and also ease of use.my $fh = IO::File "output.txt", "w" or die "Can not create output: $!"; print $fh "Hello world!\n"; undef $fh;
|
|---|