This is a very basic problem and I've tried many different ways to make this work. I've looked at References quick reference by tye, perlref and checked a few books, but can't find anything quite like my code.

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:

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 results look like this:
$VAR1 = { 'ABC' => [ 'f1', 'f2', 'f3' ], 'DEF' => [ 'f1', 'f2' ] }; $VAR2 = [ $VAR1->{'ABC'} ]; $VAR1 = [ [ 'f1', 'f2', 'f3' ] ];
The problem is, I want the last dump to be a plain array, which should look like the following:
$VAR1 = [ 'f1', 'f2', 'f3' ];
Can someone please show me where I've gone astray? Thanks.

In reply to Referencing a HoA by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.