in reply to two regexes in one function call

In your example, s// is modifying $data twice within one statement.

Could it be that, as a general rule, the results of modifying a variable twice in a statement is unspecified? This might explain the Perl implementation dependent behavior discussed above. It certainly seems to be the case for the increment and decrement operator. Perhaps it is also true for s// and other operators that modify the variable upon which they operate? As stated in perlop (I've bolded the key words):

Note that just as in C, Perl doesn't define when the variable is incremented or decremented. You just know it will be done sometime before or after the value is returned. This also means that modifying a variable twice in the same statement will lead to undefined behaviour.

Best, beth

Replies are listed 'Best First'.
Re^2: two regexes in one function call
by ikegami (Patriarch) on Jul 28, 2009 at 20:34 UTC

    That's not the problem. For starters, neither s/// modify the variable.

    There's problems with that quote anyway. Perl *does* define the operand evaluation order for some operators (namely the comma and the logical operators), it's regularly relied upon for some other operators (assignment operators and method call), and it's predictable for the rest.

    Update: Added second paragraph.