in reply to Re: how extract and group data in a array
in thread how extract and group data in a array

Nice. For the record, this can be simplified a little using Perl’s range operator in static context:

use strict; use warnings; my @dd = qw/AA JJ CC M 1 1 3 4 D JJ 1 1 D M 3 3 4 D C M 3 3 3 D/; my @group; for (@dd) { if ($_ eq 'M' .. $_ eq 'D') # or: if (/^M$/ .. /^D$/) { push @group, $_; } elsif (@group) { print join(' ', @group), "\n"; @group = (); } } print join(' ', @group), "\n" if @group;

Output:

17:41 >perl 1752_SoPW.pl M 1 1 3 4 D M 3 3 4 D M 3 3 3 D 17:42 >

Hope that’s of interest,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,