First, because you're shifting single items inside of new(), both arrays need to be arefs when sent in. In your get__Array methods, you want to return the array that you have stashed in $self->{_ArrayN};. Here's a full example that shows how you can return either a reference to the array you have stored, or return it as a list instead:

use warnings; use strict; package Test; sub new { my $class = shift; my $self = { _DataMember0 => shift, _Array0 => shift, }; bless $self, $class; } sub get__Array0{ my $self = shift; if (wantarray){ # caller wants a list (dereference the ref before return) return @{ $self->{_Array0} }; } else { # caller wants an array reference return $self->{_Array0}; } } package main; my $aref = [1, 2, 3]; my $test = Test->new(1, $aref); # get it as a list my @array = $test->get__Array0(); # parens not needed, only used for c +larity # get an aref instead my $array_reference = $test->get__Array0(); print "$_\n" for @array; print "$array_reference->[0]\n";

In reply to Re: Array as Object Data Member by stevieb
in thread Array as Object Data Member by fattahsafa

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.