Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: use Fatal ':void' vs. $!

by rblasch (Monk)
on Jun 13, 2006 at 14:38 UTC ( [id://555055]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://555055]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2024-04-23 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found