in reply to Re: Matching and order of evaluation
in thread Matching and order of evaluation

I thought that it was a simple statement but wasn't sure. In fact, I don't know whether your simple example is safe for all $var - does it become unsafe if $var has get-magic or set-magic?
  • Comment on Re: Re: Matching and order of evaluation

Replies are listed 'Best First'.
Re: Matching and order of evaluation
by Abigail-II (Bishop) on Oct 27, 2003 at 21:55 UTC
    Well, if there's magic involved, anything could happen - after all, you're then back into "user" land. But, assuming nothing weird happens during the magic, it should be fine. The order will be: FETCH, evaluate RHS expression, STORE.

    Abigail

      So then, so that I'm clear - if I control the input and know its going to be mundane perl then I can do what I've always done ($x = $x + 1) but if I'm writing module code that accepts input from the user then I've got to be pessimistic and use a temp variable or something to shield myself from the user's magic?
        You won't be able to shield yourself from the user's magic. You got to get the value of variable, and if it has get-magic, it's magic will be triggered, whether you put the value in a tmp variable, or in an expression. Furthermore, at the end, you're going to put the value back, so any set-magic will be triggered. Regardless whether you used a temp variable in between. But even if there's a way to avoid magic (in some cases, the use of temp variables can circumvent overload magic), in general you shouldn't. The user put that magic there for some reason (persistency, for instance), and would not expect a module to go out of its way to avoid it.

        Abigail