in reply to tied, or modified?

perl -e 'tied sub {}->()'
doesn't parse differently than
perl -e 'tied( sub {}->() )'
and neither produce the "Can't modify reference constructor" error.

I think you tried
perl -e 'tied { sub {}->() }'

perl -e 'tied { sub {} }->()'

which is what Deparse gives for the above two programs. This is a bug in Deparse. It's not representative of the opcode tree produced by the first two programs.

Replies are listed 'Best First'.
Re^2: tied, or modified?
by JadeNB (Chaplain) on Nov 13, 2009 at 23:37 UTC

    Hmm, Perl 5.8.9 gives me

    $ perl -MO=Deparse -e 'tied sub {}->()' tied {sub { } }->(); -e syntax OK
    which gives a different error:
    $ perl -e 'tied { sub {} }->()' Not a subroutine reference at -e line 1.

    The code you mention doesn't compile:

    $ perl -e 'tied { sub {}->() }' Can't modify anonymous hash ({}) in tied at -e line 1, at EOF Execution of -e aborted due to compilation errors.

    Thanks for taking the time to think about this. I've cut and pasted these straight from the command line to avoid further incidents. :-)

      which gives a different error:

      As it should. Like I said, it's a bug in Deparse.

      An anonymous hash is the anonhash opcode.

      $ perl -MO=Concise,-exec -e'{}' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <0> pushmark s 4 <@> anonhash vK* 5 <@> leave[1 ref] vKP/REFC -e syntax OK

      Note the lack of anonhash in the code that's actually produced by tied sub {}->().

      $ perl -MO=Concise,-exec -e'tied sub {}->()' 1 <0> enter 2 <;> nextstate(main 2 -e:1) v:{ 3 <0> pushmark s 4 <0> pushmark sRM 5 <$> anoncode[CV ] lRM 6 <1> refgen sK/1 7 <1> rv2cv sK/NO() 8 <1> entersub[t2] sKRMS/NO(),TARG,1 9 <1> tied vK/1 a <@> leave[1 ref] vKP/REFC -e syntax OK

      Deparse is wrong to add an anon hash constructor. Therefore, trying to execute the output of Deparse makes no sense.