Dear Sirs,

Given this array:

my @array = qw (    A  B  C  D  E   );

I want to enumerate all its possible ranges
throughout the elements. Such that it gives
the following desired answer, that look like this ( I manually crafted it):.

my $ans =       [ 'A',
                 'B',
                 'C',
                 'D',
                 'E',
                 'AB',
                 'ABC',
                 'ABCD',
                 'ABCDE',
                 'BCD',
                 'BCDE',
                 'CD',
                 'CDE',
                 'DE' ];

Later, I also want to  extend this
to deal with AoA as an input. But with
the same concept.

Is there an efficient way to achieve it?
I truly do not  know how to go about it.
Really hope to hear from you again.

Hello Edward

The below will produce what you want. Hope this helps.

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my @array = qw (    A  B  C  D  E   );
my @data;

for my $i (0..$#array) {
my $str = '';
for my $j ($i..$#array) {
 $str .= $array[$j];
 push @data, $str;
}
}

print Dumper [EMAIL PROTECTED];

__END__
*** Output
C:\perlp>perl t6.pl
$VAR1 = [
         'A',
         'AB',
         'ABC',
         'ABCD',
         'ABCDE',
         'B',
         'BC',
         'BCD',
         'BCDE',
         'C',
         'CD',
         'CDE',
         'D',
         'DE',
         'E'
       ];

C:\perlp>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to