in reply to Data inheritance
I think you're asking how to store an array to the object.
There's no reason to override the parent's object construction.
If you are using hash based objects, then you can't store an array into it directly. Hashes can only have scalars for values. You could store a reference to an array, though. [] creates an array and returns a reference to that array.
You're getting a syntax error because that's not even close to how one assigns to a hash via a reference.
package Base; use strict; use warnings; sub new { my $class = shift; return bless({}, $class); } 1;
package Child; use strict; use warnings; use Base; our @ISA = qw( Base ); sub new { my $class = shift; my $self = $class->SUPER::new(); $self->{nums} = [qw( 1 2 )]; return $self; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Data inheritance
by perlbaski (Sexton) on Sep 23, 2011 at 21:00 UTC | |
by ikegami (Patriarch) on Sep 23, 2011 at 21:04 UTC | |
by perlbaski (Sexton) on Sep 23, 2011 at 21:15 UTC | |
by ikegami (Patriarch) on Sep 23, 2011 at 21:17 UTC | |
by perlbaski (Sexton) on Sep 23, 2011 at 21:27 UTC | |
by ikegami (Patriarch) on Sep 23, 2011 at 22:47 UTC | |
by perlbaski (Sexton) on Sep 23, 2011 at 21:12 UTC | |
by ikegami (Patriarch) on Sep 23, 2011 at 21:13 UTC |