in reply to A better (ie.more concise) way to write this?
I'd do it like this:
@a = map { ++$_ % 10 } @a;
If I'm missing the point and you're explicitly wanting to only alter a subset of the items, a slice'll adapt it:
@a = map {++$_ % 10 } @a[0-5,7];
Update: If the point is to modify it in place, I like the AM post above...
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A better (ie.more concise) way to write this?
by Anonymous Monk on Dec 13, 2013 at 17:35 UTC | |
Re^2: A better (ie.more concise) way to write this?
by BrowserUk (Patriarch) on Dec 13, 2013 at 18:23 UTC | |
by Laurent_R (Canon) on Dec 13, 2013 at 18:55 UTC |
In Section
Seekers of Perl Wisdom