in reply to use Fatal ':void' vs. $!

Consider this example.

use strict; use warnings; use Fatal qw(:void open); # set $! to some random number; we just want to see # if it is modified $! = 42; print "$!\n"; open my $f, '<no_such_file' or die "Can't open no_such_file: $!";

The output is as follows.

Illegal byte sequence Can't open no_such_file: Illegal byte sequence at t.pl line 10.

$! doesn't seem to get modified. Taking a look at Fatal.pm, one sees the following at about line 121:

local(\$", \$!) = (', ', 0);

$" and $! are localized in the replacement subroutine, open in this example. Removing above line, and running the example again yields the following.

Illegal byte sequence Can't open no_such_file: No such file or directory at t.pl line 10.

This seems to be the desired outcome.

I don't use Fatal, so I can't tell if the localized $! is a bug or a feature.

Replies are listed 'Best First'.
Re^2: use Fatal ':void' vs. $!
by Zaxo (Archbishop) on Jun 13, 2006 at 15:35 UTC

    I think you have it. It looks to me like,

    $code = <<EOS; sub$real_proto { local(\$", \$!) = (', ', defined(wantarray)? \$! : 0); EOS
    would fix it. Untested.

    After Compline,
    Zaxo