note
perlfan
Maybe you just want something like this;
<code>
package Foo;
sub new {
my $pkg = shift;
my %self = @_;
my $self = bless \%self, $pkg;
# do stuff to $self (now a __PACKAGE__)
return $self;
}
1;
</code>
Then,
<code>
use Data::Dumper ();
my $foo = Foo->new(a => 1, b => 2, c => [qw/apple banana grape/]);
print Data::Dumper::Dumper(\$foo)
</code>
Output:
<code>
$VAR1 = \bless( {
'b' => 2,
'c' => [
'apple',
'banana',
'grape'
],
'a' => 1
}, 'Foo' );
</code>
If you want the basis for a <code>Foo</code> to be an array ref, then,
<code>
package Foo;
sub new {
my $pkg = shift;
my @self = @_;
my $self = bless \@self, $pkg;
# do stuff to $self (now a __PACKAGE__)
return $self;
}
1;
</code>
Output:
<code>
$VAR1 = \bless( [
'a',
1,
'b',
2,
'c',
[
'apple',
'banana',
'grape'
]
], 'Foo' );
</code>
Note, <code>=></code> is taken as a <i>comma</i> when an array is on the LHS of the assignment (<code>=</code>). Hashes can be treated as even-sized arrays - or arrays of <i>tuples</i> (i.e., <code>key => val</code>).
11135194
11135194