in reply to Re: Ignore a range of numbers ina List
in thread Ignore a range of numbers ina List
I was thinking along lines similar to Marshall:
I suspect this logic can be cleaned up significantly. I'd like get something approaching tybalt89's solution.c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "use constant { START => 6, STOP => 7, }; ;; my $aref = [ 6, 7, 1, 6, 8, 9, 7, 2, 6, 98, 99, 7, 3, 7, 4, 6, 5, ]; dd $aref; ;; my @final; my $maybe_truncate; ;; for my $element (@$aref) { if (defined $maybe_truncate) { if ($element == STOP) { $#final = $maybe_truncate; undef $maybe_truncate; next; } } else { if ($element == START) { $maybe_truncate = $#final; } } push @final, $element; } ;; dd $aref; dd \@final; " [6, 7, 1, 6, 8, 9, 7, 2, 6, 98, 99, 7, 3, 7, 4, 6, 5] [6, 7, 1, 6, 8, 9, 7, 2, 6, 98, 99, 7, 3, 7, 4, 6, 5] [1, 2, 3, 7, 4, 6, 5]
Give a man a fish: <%-{-{-{-<
|
---|