in reply to Re: 'strict refs' + 'strict sub' = suck.
in thread 'strict refs' + 'strict sub' = suck.

Roger, you've pimped the use of IO::File over open once before in Re: Removing duplicates from list yet you never state why you think IO::File is better. I'm honestly curious as to why you prefer one over the other. Is it just because IO::File uses OO syntax?

-- vek --

Replies are listed 'Best First'.
Re: Re: Re: 'strict refs' + 'strict sub' = suck.
by Roger (Parson) on Oct 26, 2003 at 00:05 UTC
    Since Perl 5.6.0 we can perform file operations using a scalar - which is quite convenient to pass around in function calls. For example -

    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.
    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.
    my $fh = IO::File "output.txt", "w" or die "Can not create output: $!"; print $fh "Hello world!\n"; undef $fh;
    My preference of IO::File over open is on the Perl version compatibility and also ease of use.

    This is only my personal perference however.