Hi All, I'm an inexperienced perl coder and could really use some help here.

I'm trying to connect to a series of machines via ssh, call a script on each that returns formatted data and process the data in turn. This sub is used to retrieve the data from each machine and store it in a hash...

sub get_remote_file { print "Retrieving data file..."; my @site_data; chomp( @site_data = `$conx` ); if ( $? >> 8 ) { print "Failed!\n"; } else{ print "Success!\n"; } for $line( @site_data ) { ( $name, $filepath, $mod, $md5 ) = split( "\,", $line ); $site_data{$name} = ["$filepath", "$mod", "$md5"]; } @site_data = (); }
Which is called from within:
foreach $client ( @clients ) { my ( %site_data, %office_data ); print "Performing Sentinel check on $client\n"; get_client_configs( $client ); print "Retrieving data from site...\n"; get_remote_file; generate_local_data; compare_files; print "Completed Sentinel check on $client\n"; }

get_client_configs updates the $conx variable among other things. The $conx variable holds the connection string, eg 'ssh host ~/myscript'.

The problem I'm having is that the first time through the loop everything works fine and the hash is properly populated. However on every subsequent call the @site_data ends up with a single element containing all the data returned from the script on the remote machine. As you can see it screws up the populating of the hash.

Can anyone please help? Before you say it I cannot install any modules to help with this, it's not my machine.

In reply to Processing data from SSH stream by Spasticus

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.