Hello vels, and welcome to the Monastery!

Here is some simple code to create a 3D array, pass it into and out of a subroutine, and print it using the module Data::Dump:

#! perl use strict; use warnings; use Data::Dump; my @array3d = ( [ [ 'a', 'c', 'e', ], [ 'f', 'h', 'j', ], [ 'k', 'm', 'o', ], ], [ [ 'A', 'C', 'E', ], [ 'F', 'H', 'J', ], [ 'K', 'M', 'O', ], ], ); dd \@array3d; my $array_ref = multi(\@array3d); dd $array_ref; print "$array_ref->[0][2][1]\n"; $array_ref->[0][2][1] = 'Change 2'; dd $array_ref; sub multi { my ($array3d_ref) = @_; $array3d_ref->[1][1][2] = 'Change 1'; return $array3d_ref; }

Output:

13:12 >perl 749_SoPW.pl [ [["a", "c", "e"], ["f", "h", "j"], ["k", "m", "o"]], [["A", "C", "E"], ["F", "H", "J"], ["K", "M", "O"]], ] [ [["a", "c", "e"], ["f", "h", "j"], ["k", "m", "o"]], [["A", "C", "E"], ["F", "H", "Change 1"], ["K", "M", "O"]], ] m [ [["a", "c", "e"], ["f", "h", "j"], ["k", "Change 2", "o"]], [["A", "C", "E"], ["F", "H", "Change 1"], ["K", "M", "O"]], ] 13:12 >

Note the -> in the expression $array3d_ref->[1][1][2]. This is required; see:

Also, please put your code within <code> ... </code> tags, as this makes it easier for the monks to read.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Returning Multidimensional array from subroutine to main code by Athanasius
in thread Returning Multidimensional array from subroutine to main code ; by vels

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.