I have tried various combinations of @%$s but I cannot get this to work. The full expression works, but how do I split it up into variables?
print "BIGexp ", $tables{"grp"}[1]{_name}, "\n"; # OK, prints part
my @cols = $tables{"grp"};
print "COLS ", @cols, "\n"; # prints array
my %col = %cols[1];
print "COLvar ", %col, " ", "\n"; #prints 1 ?
print "COLexp ", $cols[1]{_name}, "\n"; ######## Fails, uninitialized.
I want to represent database schemas. So a map of tables, each containing an array of columns, each of which is a map. Here is the full fragment.
my %tables=();
my $columns; # array
sub addTable {
my @cols = ();
$tables{$_[0]} = \@cols;
$columns = \@cols;
}
sub addColumn {
my %col = (_name => $_[0], _typ => $_[1]);
push(@$columns , \%col);
}
addTable("grp");
addColumn("id", "serial");
addColumn("part", "integer");
addTable("tab2");
addColumn("foo2", "varchar");
addColumn("bar2", "integer");
print "BIGexp ", $tables{"grp"}[1]{_name}, "\n"; # OK, prints part
my @cols = $tables{"grp"};
print "COLS ", @cols, "\n"; # prints array
my %col = %cols[1];
print "COLvar ", %col, " ", "\n"; #prints 1 ?
print "COLexp ", $cols[1]{_name}, "\n"; ######## Fails, uninitialized.
I am new to Perl and have yet to become "Perl minded" :(. Any help much appreciated.