develooper Front page | perl.perl5.porters | Postings from September 2018

Re: [perl #133517] $! cannot be localized by doing a copy

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
September 14, 2018 19:24
Subject:
Re: [perl #133517] $! cannot be localized by doing a copy
Message ID:
CAHhgV8iFq72jfWkUmrLX1A4GSfHDZgd19aS0bZpM7sJ3hymc1Q@mail.gmail.com
On Fri, Sep 14, 2018 at 7:21 PM Atoomic (via RT)
<perlbug-followup@perl.org> wrote:
> We recently discovered this issue while updating Test::Trap to 0.3.3
> which by trying to localize $!, in fact corrupted it using a simple
>
>     local ($!, $^E) = ($!, $^E);
>
> view https://rt.cpan.org/Public/Bug/Display.html?id=127112 for more details
>
> So I performed some basic tests using multiple perl versions from 5.10 to
> 5.28
> and looks like they all behave in the same way (which is good).
>
> But I think it's weird that $! cannot be localized performing a copy
>
> perl -e'$! = 4; do { local $! = $!; 1; }; print 0 + $!'
> 0
>
> Another variable would work fine and preserve its original value
> perl  -e'our $x= 4; do { local $x = $x; }; print 0 + $x'
> 4
>
> of course a workaround could be
> perl -e'$! = 4; do { local $! = $! . q//; 1; }; print 0 + $!'
> 4
>
> or a less convoluted by doing a manual copy
>
> perl -e'$! = 4; do { my $copy = $!; local $! = $copy; 1; }; print 0 + $!'
> 4
>
> At this point I'm not sure we can call it a bug... (maybe it's a feature)
> but I still want to know your opinion on this
> and you think it is worth fixing.

This is a duplicate of #119683

Leon

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About