http://qs1969.pair.com?node_id=11139098


in reply to How Perl can push array into array and then how retrieve

I'm guessing somewhat regarding what you want to achieve.

Always put strict and warnings at the top of your code. In this instance, that would have alerted you to the fact that there was something wrong with $f.

I was unsure why you wanted to increment $i inside the loop. In my version, I changed $i+=2 to $i+2.

Here's a couple of ways of doing what I think you want:

#!/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;

Output:

[[2, 1], [3, 2], [4, 3], [5, 4], [6, 5], [7, 6]]

See also: "perlintro: Arrays"; "perldsc - Perl Data Structures Cookbook"; "perllol - Manipulating Arrays of Arrays in Perl".

— Ken