Try this to see the difference between $ssh & \$ssh: use Data::Dumper;
my $ssh = login($user, $pass, $host);
print Dumper $ssh;
print Dumper \$ssh;
Objects in perl are often, but not always, references to a hash that has been "bless"ed into a particular namespace. In this case Net::OpenSSH->new returns a reference to a hash. In fact you can bless any reference - array refs, scalar refs, even sub-routine refs
It's easy to create your own blessed references
use Data::Dumper;
my $obj_ref = bless {} , 'Any::Old::Perl::Identifier';
sub Any::Old::Perl::Identifier::make_hay{
my ($self) = @_;
$self->{'foo'} = 'hay';
}
$obj_ref->make_hay();
print ref $obj_ref, "\n";
print ref \$obj_ref, "\n";
print Dumper $obj_ref;
Prints:Any::Old::Perl::Identifier
REF
$VAR1 = bless( {
'foo' => 'hay'
}, 'Any::Old::Perl::Identifier' );
You can see that the obj_ref has made hay.
Refs can be a bit confusing. Try the perlreftut tutorial in the core perl documentation.
|