I'm trying to assign an existing array to an object member variable whose type is array. This should be possible, but I cant figure out how. I will also need to extract the entire array (I know how to get an individual item by indexing). Here is sample code for what I'm trying to do - of course, this code does not produce the desired result(6):

use Class::Struct qw(struct); struct S=>[a=>'$',b=>'@']; #"b" is an array my $a=S->new; my @q=(4,6,7,99); # A local array $a->b(@q); # What I'd like to do - gives syntax err print $a->b(1) # Prints NOTHING .. hoping to see "6" $a->b($q); # Try to assign the $$q to $a->b print $a->b(2) # Prints NOTHING .. hoping to see "7" # Would also like to do my @x = $a->b; % Extract entire array

I guess I'm looking for a overloaded method "b" that accepts an array parameter. I know that $a->b($scalar,$scalar) works fine.

How should I do this ???

Edited 2003-02-28 by Ovid


In reply to Accessing ARRAYS inside objects by NetWallah

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.