in reply to Re^2: Ignore a range of numbers ina List
in thread Ignore a range of numbers ina List
use Data::Dumper; my $allow_loose6 = 1; my $aref = [1, 6, 2, 2, 7, 1, 6, 99, 99, 7]; my @new = (); my @loose = (); my $flag = 0; for (@$aref) { $flag = 1 if (!$flag and $_==6); if (!$flag) { push @new, $_; } else { push @loose, $_; } if ($flag and $_==7) { $flag = 0; @loose = (); } } $aref = \@new; if ($allow_loose6) { push @$aref, @loose; } elsif (@loose) { die "Unterminated 6 detected"; } print Dumper $aref
One world, one people
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Ignore a range of numbers ina List
by Laurent_R (Canon) on Jun 25, 2017 at 11:05 UTC | |
by AnomalousMonk (Archbishop) on Jun 25, 2017 at 16:47 UTC | |
by anonymized user 468275 (Curate) on Jun 25, 2017 at 14:01 UTC |