I created the perl script below It consist of multiple subroutines collecting seperate information. I am having a problem managing the array output scalar, I would like to see a different line input for each command and each host. This is the part as a beginner I having problem with. The hosts.txt file havng (server1, server2, server30 and the commands are one, two, three, four. Please help.
#!/usr/bin/perl use 5.010; use strict; use warnings; main(@ARGV); sub get_host # Collect the host name from a text file { open(HOST, '<', 'hosts.txt') or error("cannot open file ($!)"); my @host = <HOST>; return "@host\n"; } sub get_logon # Collect logon ID from keyboard { my $logon; print "Please Enter Logon ID:\n"; chomp ($logon =<>); return $logon; } sub get_psswd # Collect password from keyboard { my $psswd; print "Please Enter Password for hostID:\n"; chomp ($psswd =<>); return $psswd; } sub get_command # Collect the commands from a text file { open(CMD, '<', 'cmds.txt') or error("cannot open file ($!)"); my @cmd = <CMD>; return @cmd; } sub main # Command execution and export data to local file { my @host = get_host(); print @host; print "\n"; my $logon = get_logon(); print $logon; print "\n"; my $psswd = get_psswd(); print $psswd; print "\n"; my @cmds = get_command(); print @cmds; my $output = qx(cmd); open my $OUTPUT, '>>' , 'devbfs51chassisshow.txt' or die " Couldn't op +en output.txt: $!\n"; print "1plink -ssh -pw $psswd -l $logon @host @cmds"; }

In reply to Perl Array output Help by PerlCramps

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.