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 |