[tapx-dev] [commit][276] Replace bareword handle with lexical var
Sébastien Aperghis-Tramoni
maddingue at free.fr
Sun Aug 19 13:28:07 BST 2007
andy at hexten.net wrote:
> Log Message:
> -----------
> Replace bareword handle with lexical var
>
> Modified: trunk/lib/TAP/Parser/Source/Perl.pm
> ===================================================================
> --- trunk/lib/TAP/Parser/Source/Perl.pm 2007-08-19 11:09:12 UTC
> (rev 275)
> +++ trunk/lib/TAP/Parser/Source/Perl.pm 2007-08-19 11:51:35 UTC
> (rev 276)
> @@ -173,10 +173,9 @@
> $self->switches,
> );
>
> - local *TEST;
> - open( TEST, $file ) or print "can't open $file. $!\n";
> - my $shebang = <TEST>;
> - close(TEST) or print "can't close $file. $!\n";
> + open( my $th, $file ) or print "can't open $file. $!\n";
> + my $shebang = <$th>;
> + close $th or print "can't close $file. $!\n";
open(my $fh, ...) doesn't work on Perl versions before 5.6 (as shown
by your automated test report). The syntax is valid but the
filehandle isn't automatically created, you must do it by hand. The
solutions I propose in my talk WRT this is either to just create the
symbol:
use FileHandle;
open my $fh = new FileHandle, $path or die $!;
but I find this quite ugly, so the other solution is to go the OO-way:
use FileHandle;
my $fh = FileHandle->new($path) or die $!;
which has the advantage of supporting a separated mode just like the
3-args open():
use FileHandle;
my $fh = FileHandle->new($path, $mode);
# where $mode is ANSI mode: r, w, r+, etc
This last statement should work since Perl 5.002
HTH
--
Sébastien Aperghis-Tramoni
Close the world, txEn eht nepO.
More information about the tapx-dev
mailing list