in reply to Multi-Dimensional Arrays and Array References
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Data::Dumper; my $ref = [[1, 2, 3], [4, 5, 6]]; # Print an element. say $ref->[1][1]; # Add a row. push @$ref, [7, 8, 9]; # Add a column. my @column = (3.5, 6.5, 9.5); push @{ $ref->[$_] }, $column[$_] for 0 .. $#column; # The same with an array. my @array = ([1, 2, 3], [4, 5, 6]); # Print an element. say $array[1][1]; # Add a row. push @array, [7, 8, 9]; # Add a column. my $column = \@column; push @{ $array[$_] }, $column->[$_] for 0 .. $#$column; Dumper($ref) eq Dumper(\@array) or die "Different";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multi-Dimensional Arrays and Array References
by Leudwinus (Scribe) on Nov 16, 2020 at 17:59 UTC | |
by hippo (Archbishop) on Nov 16, 2020 at 18:49 UTC | |
by Leudwinus (Scribe) on Nov 16, 2020 at 18:11 UTC | |
by AnomalousMonk (Archbishop) on Nov 16, 2020 at 19:38 UTC | |
by Leudwinus (Scribe) on Nov 16, 2020 at 21:28 UTC |