It should fill whatever array you pass to it, which in this case is @name. The reason this can be done is because of the way the sub is declared, in particular, the (\@) definition means that the first parameter is an array reference. This way, instead of passing a copy of the @name array, a reference to it is passed, allowing you to manipulate it.

With that in mind, I'm surprised that you get "nothing". @name should be filled with array references, these sub-arrays that contain the various rows. Using your code, since you are not de-referencing them, you should see something like this:
ARRAY(0x80fe5a8) ARRAY(0x80fe5d2) ARRAY(0x80fe6f4)
The reason is you are printing an array reference as a string, which isn't going to work. A solution is to either use the venerable Data::Dumper or just deference it:
# Data::Dumper saves the day again use Data::Dumper; print Dumper (\@name); # De-reference it and treat it as an array foreach my $row (@name) { print join (',', @$row),"\n"; }
I'm not sure how familiar you are with references, but here's a 5 second intro:
my @array = qw[ 1 2 3 ]; my $array_ref = \@array; # Backslash makes a reference my @array_copy = @$array_ref; # @ de-references array reference $array[2] = 4; # Modifies @array directly print $array_ref->[2]; # Should be '4' now $array_ref->[1] = 5; # Modifies @array by reference print $array[1]; # Should be '5' $array_copy[1] = 6; # Modifies @array_copy, not @array print $array[1]; # Still '5'

In reply to Re^3: Fill Arbitrary Array by tadman
in thread Fill array 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.