in reply to Putting contents of an array into Object property

The other solutions mention how to do things with an array reference. That's probably what you want, but just because there are other ways (so I've heard), if you want your method to accept arrrays for whatever reason, you could do something along the following lines in your method:

sub clientcrgunit { my ($self, @stuff) = @_; $self->{clientcrgunit} = \@stuff; }

The first thing passed to the method is the reference to the object, the rest will be slurped into @stuff; if you want to accept either arrays *or* array references, you could check to see whether @stuff has one member, and if that member is a reference to an array:

sub clientcrgunit { my ($self, @stuff) = @_; if ( @stuff == 1 && ref($stuff[0] eq 'ARRAY') ) { $self->{clientcrgunit} = $stuff[0]; } else { $self->{clientcrgunit} = \@stuff; } }
perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Replies are listed 'Best First'.
(tye)Re: Putting contents of an array into Object property
by tye (Sage) on Sep 28, 2001 at 21:30 UTC

    I ++ this method. But I wanted to note that there is an extra advantage to this method over using \@stuff as advocated by several other people. Doing, for example:

    $self->{clientcrgunit}= \@stuff; @stuff= getNextBatchOfStuff();
    will cause $self->{clientcrgunit} to be modified to hold the list returned by getNextBatchOfStuff(). So, if you don't go with arturo's solution, you should probably use: $self->{clientcrgunit}= [@stuff]; instead. You can avoid this extra copying if you know that @stuff is a lexical variable that won't be modified again until it is destroyed.

            - tye (but my friends call me "Tye")