c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"my $aref = [ 6, 7, 1, 6, 8, 9, 7, 2, 6, 98, 99, 7, 3, 7, 4, 6, 5, ];
dd $aref;
;;
my @copy;
$_ == 6 .. $_ == 7 or push @copy, $_ for @$aref;
;;
dd \@copy;
"
[6, 7, 1, 6, 8, 9, 7, 2, 6, 98, 99, 7, 3, 7, 4, 6, 5]
[1, 2, 3, 7, 4]
What's supposed to happen if a "start" code for an exclusion sequence is seen, but no corresponding "stop" code is ever seen? My assumption was that no exclusion would happen. I expected
[6, 7, 1, 6, 8, 9, 7, 2, 6, 98, 99, 7, 3, 7, 4, 6, 5]
to yield
[1, 2, 3, 7, 4, 6, 5]
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |
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
| [reply] [d/l] |
What's supposed to happen if a "start" code for an exclusion sequence is seen, but no corresponding "stop" code is ever seen?
If the RHS of the flip-flop operator never gets true, then the flip-flop just stays as it is. Hence after 7,4 the 6 turns the flip-flop on, and 6,5 aren't pushed onto @copy.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
| [reply] [d/l] [select] |
Hence after 7,4 the 6 turns the flip-flop on, and 6,5 aren't pushed onto @copy.
I understand that, but what I was confused about was whether pr33 wanted the 6, 5 to appear in the output or not. pr33 seems to have answered this and related questions here. (At last! A quasi-test-based response :)
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |