Help for this page

Select Code to Download


  1. 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 } );
    
  2. or download this
    sub new {
        my( $class, $hashRef )= @_;
        my $self= bless $hashRef, $class;
        return $self;
    }
    
  3. 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 );
    
  4. or download this
    sub new {
        my( $class, $hashRef )= @_;
        my $self= bless {%$hashRef}, $class;
    ...
        return $self;
    }
    # etc.