I'm trying to make a little script with a nested "for" loop in perl. As I'm learning, at first I've done 3 for loops and it worked well. In order to make something more intelligent, I'd like to nested them but I don't know what is wrong.
If my input text is ABCDEFGHI I'd like to obtain
text 1 ABC DEF GHI
text 2 BCD EFG HI
text 3 CDE FGH I
But instead of it, my output is
text1 ABC DEF GHI ABC DEF GHI ABC DEF GHI ABC DEF GHI ABC DEF GHI ABC DEF GHI ABC DEF GHI ABC DEF GHI ABC DEF GHI
text2 BCD EFG HI BCD EFG HI BCD EFG HI
text3 CDE FGH I
Here is my script. I'm using perl 5.18.1.
use Modern::Perl '2013';
my @text1;
my @text2;
my @text3;
my $entry = shift;
my $len = length $entry;
for (my $i = 2; $i < $len; $i += 3) {
for (my $i = 1; $i < $len; $i += 3) {
for (my $i = 0; $i < $len; $i += 3) {
my $text = substr($entry, $i, 3);
push @text1, uc($text);
}
my $text = substr($entry, $i, 3);
push @text2, uc($text);
}
my $text = substr($entry, $i, 3);
push @text3, uc($text);
}
say "text1 @text1";
say "text2 @text2";
say "text3 @text3";
I've already taken a look around and here http://perldoc.perl.org/perlsyn.html#For-Loops
Thank you for any help