in reply to Re^2: creating adjacency matrix
in thread creating adjacency matrix
Each "row" is what the [@x] represents and is the return value of the map. Another set of code in this thread uses a hash table to represent the data.example of a 3x3: my @m = ([0,0,0], [0,0,0], [0,0,0]);
The main idea is to make a square matrix and then each set of letters results in two entries into that matrix. Many implementations of that idea are possible, some much shorter than what I did in this case.
Update:
This might help you to understand what is going on without a map...a map is kind of like a "tricky" foreach() loop.
This is the same thing and perhaps a more familiar form of [x][y] coordinates#!/usr/bin/perl -w use strict; use Data::Dumper; my @sq_matrix_3x3; my @list = (1,2,3); foreach (@list) { push (@sq_matrix_3x3, [0,0,0]); #creates a row with 3 elements } print "3x3 Matrix: "; print Dumper \@sq_matrix_3x3;
my @another_2D; for (my $x=0; $x<3; $x++) { for (my $y=0; $y<3; $y++) { $another_2D[$x][$y]=0; } } print Dumper \@another_2D; __END__ prints: 3x3: $VAR1 = [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ]; # print Dumper \@sq_matrix_3x3; #these both produce the same output # print Dumper \@another_2D;
|
|---|