Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts

Sunday, December 16, 2012

perl experience - ssh implement

my @key = ("/root/.ssh/id_rsa");
my $ssh = Net::SSH::Perl->new($host,
        identity_files=>\@key,
#        debug => 1
    );
$ssh->login('root');

Tuesday, April 07, 2009

perl - hash, array, reference

About hash, array, reference

solution 1,

#!/usr/bin/perl -w

use strict;

my @array;
foreach (0..9) {
handler(\@array);
}
for my $i (0..$#array) {
print $array[$i]->{key},"\n";
}

sub handler {
my ($aryhref)=@_;
my (%hash);
$hash{key}="abc";
push @$aryhref, \%hash;
}

=========================
solution 2,

#!/usr/bin/perl -w

use strict;

my @array;

my %hash;
foreach (0..9) {
ca(\%hash);
push @array, \%hash;
}
for my $i (0..$#array) {
print $array[$i]->{username},"\n";
}

sub ca {
my ($hashref)=@_;
$hashref->{username}="abc";
}

use strict;
%{hashref}->{key}
got "Using a hash as a reference is deprecated"
suggest ${hashref}{key} instead.

about Perl Module installation