note
kcott
<p>
I'm guessing somewhat regarding what you want to achieve.
</p>
<p>
Always put <c>strict</c> and <c>warnings</c> at the top of your code.
In this instance, that would have alerted you to the fact that there was something wrong with <c>$f</c>.
</p>
<p>
I was unsure why you wanted to increment <c>$i</c> inside the loop.
In my version, I changed <c>$i+=2</c> to <c>$i+2</c>.
</p>
<p>
Here's a couple of ways of doing what I think you want:
</p>
<code>
#!/usr/bin/env perl
use strict;
use warnings;
my @f;
# Modification of your code
for my $i (0..2) {
my @e = ($i+2, $i+1);
push @f, [@e];
}
# A more succinct way to achieve it
for my $i (3..5) {
push @f, [$i+2, $i+1];
}
# For demo purposes
use Data::Dump;
dd \@f;
</code>
<p>Output:</p>
<code>
[[2, 1], [3, 2], [4, 3], [5, 4], [6, 5], [7, 6]]
</code>
<p>
See also:
"[https://perldoc.perl.org/perlintro#Arrays|perlintro: Arrays]";
"[https://perldoc.perl.org/perldsc|perldsc - Perl Data Structures Cookbook]";
"[https://perldoc.perl.org/perllol|perllol - Manipulating Arrays of Arrays in Perl]".
</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-861371">
<p>— Ken</p>
</div></div>
11139097
11139097