in reply to eval segfaults when $@ isn't writable

To set $! to a constant 1, you need to give the typeglob a reference to it:

$ perl -Mwarnings -Mstrict -e'BEGIN { *! = \1; open my $fd, "< nonexis +tent"; print "$!\n"; }' 1
It's notable that the typeglob assignment to constant destroys $!'s dual value magic:
$ perl -e'$! = 1; print "$!\n"' Operation not permitted

I don't know whether the segfault is justified or a bug or simply undefined behavior. Just setting *@ = \1 (or 1) does not fire the segfault. I expect that die has some eval-like tendencies.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: eval segfaults when $@ isn't writable
by Hue-Bond (Priest) on Jul 04, 2006 at 10:22 UTC
    To set $! to a constant 1, you need to give the typeglob a reference to it:

    What I meant was not to assign the constant 1 to $!, but to make $! an alias for $1, which is read only too:

    *! = 1; "text" =~ /.(..)/; print "$!\n"; __END__ ex
    It's notable that the typeglob assignment to constant destroys $!'s dual value magic:
    $ perl -e'$! = 1; print "$!\n"'

    I don't get this. There's no typeglob assignment in your example. Maybe a typo? If you meant *! = 2 then you'll get an alias for $2, as expected. So no $! magic. (Thank you anyway for remembering me that there's a CUFP I wanted to share :)).

    --
    David Serrano

      The $! = 1; fragment was just to demonstrate the dual value magic - compare to the example before that.

      After Compline,
      Zaxo

        Then it isn't a typeglob assignment, and no magic is lost. This is the same code as yours, using errno 111 instead of 1:

        $ perl -e'$! = 111; print "$!\n"' Connection refused

        Either you were fooled by the "Operation not permitted" error (which is unlikely since it isn't a Perl error according to perldiag), or I still don't get your point.

        --
        David Serrano