- or download this
# Pass by value:
$obj= My::Class->new( %hash );
$obj= My::Class=>new( key=>"value", key2=>$value2 );
# vs. pass by reference:
$obj= My::Class->new( \%hash );
$obj= My::Class=>new( { key=>"value", key2=>$value2 } );
- or download this
sub new {
my( $class, $hashRef )= @_;
my $self= bless $hashRef, $class;
return $self;
}
- or download this
my %hash= ( key=>"value", key2=>$value2 );
my $obj1= My::Class->new( \%hash );
$hash{key}= "cheap"; # This changes $obj1!
my $obj2= My::Class->new( \%hash );
- or download this
sub new {
my( $class, $hashRef )= @_;
my $self= bless {%$hashRef}, $class;
...
return $self;
}
# etc.