note
dsheroh
Try it and see.
<p>
As written, this won't compile under strict because <c>$self</c> doesn't exist outside of <c>new</c>, so I've removed that. The <c>$self</c> from within <c>new</c> is returned as its output and assigned to <c>$obj</c>, so I think where you wrote <c>$obj->{$self}</c>, you really just meant <c>$obj</c>.
<p>
With that minor adjustment and adding a call to Data::Dumper to show what's in <c>$obj</c>, the code becomes<c>
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
package a;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
package main;
my $obj = a->new;
$obj->{avalue} = 10;
print Dumper($obj);
</c>
and produces the output
<c>
$VAR1 = bless( {
'avalue' => 10
}, 'a' );
</c>
Of course, as already mentioned, it would be much better OO practice to create an accessor for <c>avalue</c> instead of working directly with the object's internals, but at least you now know a way to see whether your objects contain the data you expect them to.
1007018
1007018