Respected Monks & Gurus - I am newbie, learning the ways of perl. I am trying to pass a hash to the subroutine, one of the keys of hash is an array of hashes. I am unable to access the array properly. Heres my code:
sub do_ssh2 { my ($host,$server) = @_; my $username = $$server{"username"}; my $passwd = $$server{"passwd"}; my @cmdarr = $$server{"cmds"}; # <-is this correct my ($stdout, $stderr, $exit); my $ssh = Net::SSH::Perl->new($host, debug => 1); eval {$ssh->login($username, $passwd)}; if ($@) {logit ("ERROR: Wrong password for $host"); $$server{"stat +us"}="Y";} else {logit ("INFO: Logged in $host");$$server{"status"}="N";} eval {$ssh->login($username, $passwd)}; for (my $i=0; $i < @cmdarr; $i++) { my %cmdhash=$cmdarr[$i]; my $cmdname= $cmdarr[$i]{cmdname}; # doesnt work right print "\n\n$cmdarr[$i]{cmdname}\n\n"; eval{($stdout, $stderr, $exit) = $ssh->cmd($cmdname)}; if ($@) { logit ("ERROR: Some error, running $cmdname on $host"); $$server{"cmds"}[$i]{status}="N"; } else { logit ("INFO: executed $cmdname on $host"); $$server{"cmds"}[$i]{status}="Y"; $$server{"cmds"}[$i]{stdout}="$stdout"; $$server{"cmds"}[$i]{stderr}="$stderr"; $$server{"cmds"}[$i]{exit}="$exit"; } } } my %hosts=csv2hash("server_02.csv"); my $s=$hosts{"f8.lab.x.httpd.in"}; do_ssh1("f8.lab.x.httpd.in",$s);
The error that I am see is:
Reference found where even-sized list expected at ./Perl-1.pl line 121 +. Pseudo-hashes are deprecated at ./Perl-1.pl line 123.
The %hosts hash is of the following form:
%hosts = ( "s192.lab.x" => { status => "Y", username => "pluto", passwd => "ada232mok", cmds =>[ {cmdname => "uname",}, {cmdname => "pwd",}, ] }, "f8.lab.x.httpd.in" => { status => "Y", username => "pluto", passwd => "grs992ksj", cmds =>[ {cmdname => "uname", status => "Y", stdout => "Linux", stderr => "", exit => "0",}, {cmdname => "pwd", status => "Y", stdout => "/home/apps/plutarch", stderr => "", exit => "0",}, ] }, "sap.lab23.comp.iitd.x" => { status => "Y", username => "pluto", passwd => "ree212pkt", cmds =>[ {cmdname => "uname", status => "Y", stdout => "Linux", stderr => "", exit => "0",}, {cmdname => "pwd", status => "Y", stdout => "/home/apps/plutarch", stderr => "", exit => "0",}, ] }, );

In reply to Pseudo-hashes & Hashes by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.