BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
You have a (compound) variable that you want to increment and then modulate (ie. bound with modulus some number):
@a = ( 1 .. 10 );; $a[$_] = ( $a[$_]+1 ) % 10 for 0 .. 9;; print @a;; 2 3 4 5 6 7 8 9 0 1
Instinct wants ++$a[$_] %= 10 for 0 .. 9; to work. It doesn't.
Of course there is $a[$_] = ++$a[$_] % 10 for 0 .. 9;; which works, but is hardly better, especially when $a[$_] might be more like:
.$things{ $thing }{$someotherkey}[$someindex]{$somekey}[ $_ ]
A better way?
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Back to
Seekers of Perl Wisdom