in reply to Generating a Pattern
Here's my version:
Update: Use [-1] instead of [$#na]. Cool, learned a new thing!
Update: use ?: instead of if/then
It does not move elements around (assuming push/pop are doing the natural thing) and has only one temporary copy.@a = (1); for (1..10) { print "@a\n"; @na=(); for (@a) { $na[-1] == $_ ? $na[-2]++ : push @na, (1, $_) } @a=@na; }
Update: Use [-1] instead of [$#na]. Cool, learned a new thing!
Update: use ?: instead of if/then
In Section
Cool Uses for Perl