in reply to Re: Re: Incrementing a Hash Value
in thread Incrementing a Hash Value

There are very good reasons to let things undefined. If you specify things, it's hard to change the behaviour. Undefined behaviour can change (and history has shown that it does).

Perl doesn't have one source code, I've 192 versions of Perl installed on my computer - all with a different source code.

Abigail

Replies are listed 'Best First'.
Re: Re: Incrementing a Hash Value
by Sifmole (Chaplain) on Jun 14, 2002 at 16:37 UTC
    Wow! how do you keep straight which one is which?
    And do any of them handle $i = $i++; in any way other than the way I described?
Re: Re: Incrementing a Hash Value
by marvell (Pilgrim) on Jun 14, 2002 at 16:41 UTC
    192, Wow!

    There is a good reason for leaving things undefined if there is some benefit in implementing the process in different ways. It seems to me that that was what happened in C.

    The thing about C, and C++ today, is that the compilers branched off implementing the same standard (including its undefined components) individually.

    Perl, onm the other hand is a unidirectional implementation, as far as I can tell. I don't think there are people out there defining their own aspects of perl and releaseing their own version, are there?

    Perl is implemented in C, not by C, so perl does not suffer from the same "undefined" qualities that C does, unless there is a specific branched version of perl.

    It may be the case that some past versions of perl exhibit different behaviour, in context, but is that bug or feature?

    C specifically states this as undeifned. I think if perl did the same, your point would be valid. Otherwise, if the behaviour is differnt, then that means people are doing their own thing.

    --
    Steve Marvell

      C specifically states this as undeifned. I think if perl did the same, your point would be valid.
      From man perlop
          "++" and "--" work as in C.
      

      Convinced?

      Abigail

        No, because I can actually read perlop and find the following information right in the next paragraph.
        The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern `/^[a-zA-Z]*[0-9]*$/', the increment is done as a string, preserving each character within its range, with carry: print ++($foo = '99'); # prints '100' print ++($foo = 'a0'); # prints 'a1' print ++($foo = 'Az'); # prints 'Ba' print ++($foo = 'zz'); # prints 'aaa'
        And that certainly doesn't look like the behavior of any C compiler I ever worked with!

        So it works  as in C except obviously where it doesn't.

        That is, if placed before a variable, they increment or decrement the variable before returning the value, and if placed after, increment or decrement the variable after returning the value."

        I don't think that's in the same spirit, do you?

        --
        ¤ Steve Marvell