in reply to Re: goto HACK
in thread goto HACK

Note that $time++ modifies the element of @times, since 'for' makes $time an alias of each element.

That's kinda creepy! I assumed declaring the var was making a copy of the element that wouldn't change the array. I can't believe I never noticed that... and the same with hash values, but not keys?

Replies are listed 'Best First'.
Re^3: goto HACK
by dave_the_m (Monsignor) on Sep 25, 2018 at 11:53 UTC
    Yes, the keys function returns temporary copies of the keys while values returns the actual values. So
    $_++ for @a; # modifies each element of @a $_++ for values %hash; # modifies every value of %hash $_++ for keys %hash; # doesn't do anything useful

    Dave.