I wrote a simple code to solve your problem using this datastructure; it may be useful for you.@ary = ( [1,2], [2,3], [3,3] #other data )
#!/usr/bin/perl use warnings; use strict; my @ary= map { chomp; [split] } split /\n/, <<NUMS; #sample input dat +a 1 2 2 3 3 3 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 3 12 0 13 0 14 4 NUMS my @result; my @buffer; my $xmax = $ARGV[0] || 4; #get the xmax value from the command line my $lasty; foreach my $pair (@ary) { if ($pair->[1] != 0) { if (@buffer >= $xmax) { push @result, @buffer; @buffer = (); } if (@buffer && $lasty != $pair->[1]) { push @result, @buffer; @buffer = (); } if (@buffer && $lasty == $pair->[1]) { push @result, map { [$_->[0], $lasty] } @buffer; @buffer = (); } $lasty = $pair->[1]; push @result, $pair; next; } push @buffer, $pair; } print join "\n", map { "@$_" } @result; print "\n";
In reply to Re: A Perl-specific solution for a gap bridging problem?
by Ieronim
in thread A Perl-specific solution for a gap bridging problem?
by a11
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |