Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This is the closest I have come, but I end up with a reference to an array instead of an array for @fields. I've used similar structures before but not exactly in this way:
The results look like this:use strict; use warnings; use Data::Dumper; my @fields; GetTables('ABC', \@fields); print Dumper(\@fields); sub GetTables { my ($table_name, $aref) = @_; my %tables = ( 'ABC' => [ qw( f1 f2 f3) ], 'DEF' => [ 'f1', 'f2' ], ); @$aref = $tables{$table_name}; ## originally I had the following, but it didn't work ## $aref = $tables{$table_name}; print Dumper(\%tables, $aref); }
The problem is, I want the last dump to be a plain array, which should look like the following:$VAR1 = { 'ABC' => [ 'f1', 'f2', 'f3' ], 'DEF' => [ 'f1', 'f2' ] }; $VAR2 = [ $VAR1->{'ABC'} ]; $VAR1 = [ [ 'f1', 'f2', 'f3' ] ];
Can someone please show me where I've gone astray? Thanks.$VAR1 = [ 'f1', 'f2', 'f3' ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Referencing a HoA
by BrowserUk (Patriarch) on Jun 02, 2003 at 02:28 UTC | |
by Anonymous Monk on Jun 02, 2003 at 02:36 UTC | |
|
Re: Referencing a HoA
by educated_foo (Vicar) on Jun 02, 2003 at 02:34 UTC | |
by edoc (Chaplain) on Jun 02, 2003 at 02:44 UTC | |
by Anonymous Monk on Jun 02, 2003 at 02:52 UTC |