http://qs321.pair.com?node_id=1193493


in reply to Re^2: Ignore a range of numbers ina List
in thread Ignore a range of numbers ina List

Building upon your very elegant solution, but changing it somewhat so it now adds to the valid output a sequence at the end that starts with a 6 but never gets ended by a 7.

use Modern::PBP::Perl; my $aref = [1, 6, 2, 2, 7, 1, 6, 99, 99, 7, 1, 2, 6, 9, 8, 6, 5]; my @copy; my @stack; (($_ == 6 .. $_ == 7) and push @stack, $_) or (push @copy, $_ and @sta +ck=()) for @$aref; push @copy, @stack; use Data::Dumper; print Dumper \@copy;

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics