in reply to Re^9: localizing lexical without messing with tie ?
in thread localizing lexical without messing with tie ?

no named parameters and your code was - AFAI understood- basically about an automatic undoing of localization.

UPDATE: oversaw the readmore-part, I'm going to have a closer look at it, but as I said tied vars are really an edgecase, it's over-optimization to care about it now and to invest so much code.

No need for that I can undo it explicitly.

The code I posted using untie does exactly what I need for pack-vars.

> There are a lot more magic variables than just tied ones, but you're not likely to find them on lexicals without putting it on them explicitly.

Could you show me an example with pack-vars where magic (other than tie) results in problems after an explicit local?

DB<1> sub tst { local $_[0]; $_[0]=10 } DB<2> $a=1 DB<3> tst $a DB<4> print $a 1

Cheers Rolf

Replies are listed 'Best First'.
Re^11: localizing lexical without messing with tie ?
by ikegami (Patriarch) on Sep 11, 2010 at 02:11 UTC

    no named parameters

    I have no idea what you mean since the entire purpose of tst in the code you posted is to provide named parameters (using a bad syntax). Could I buy a verb please?

    UPDATE: oversaw the readmore-part,

    It's not behind a readmore.

    Could you show me an example with pack-vars where magic (other than tie) results in problems after an explicit local?

    tie is the Pure Perl interface to Magic. It's implemented using Magic, so anything tie can do, so can Magic.

    You're looking for any magic that has a side-effect that isn't undone by the end of the following:

    my $saved = $magical; ... $magical = ...; ... $magical = $saved;
      Named parameters in perl lingo are something like

       tst(-named=> parameter)

      I'm experimenting with functional programming and manipulating closures.

      (Update: But if you call $a and $b in sort {} "named parameters", then yes.)

      > Could I buy a verb please?

      I'm reluctant to deepen this discussion, many people here have a more emotional attitude about the "right way to do it".

      (this results normally in useless flames where I won't/can't compete)

      > (using a bad syntax)

      sic!

      > You're looking for any magic that has a side-effect that isn't undone by the end of the following:

      my $saved = $magical; ... $magical = ...; ... $magical = $saved

      Yes I'm trying to prevent possible conflicts and having a more fault-tolerant design,thats why I'm forbidding tied vars.

      UPDATE: BTW pos can be handled!

      sub dont_mess_pos { my $vr=\$_[0]; my $pos=pos($$vr); my $s=$$vr; $_[0]=42; $$vr=$s; pos($$vr)=$pos }

      DB<80> my $a="xxx";scalar ($a=~/x/g);print pos($a); tst $a; print $a +,pos($a) 1xxx1

      Cheers Rolf

        Named parameters in perl lingo are something like tst(-named=> parameter)

        That's one means of achieving named parameters. (It also provides named arguments.) However, the method that was mentioned was Sub::Parameters. It's much closer to what you want. There might be others; I just mentioned the first I found.

        many people here have a more emotional attitude about the "right way to do it".

        What's the "right way" is a matter of debate because. However, some ways are clearly bad ways of doing it, such as having to declare the callee's parameters in a scope that's visible to both the callee and the caller.