Honestly, I find it very hard to read your code (and so, hard to debug) because it's not structured well. Consider refactoring it a bit, so you have something like this:

# Top level my $choice = get_choice(); do_ip_manual() if $choice == 1; do_ip_fromfile() if $choice == 2; # Lower level sub do_ip_manual { my ($user, $pass) = get_auth(); ... } # Even lower level ...

... instead of lots of long if/else blocks.

It'd be easier to debug failures if you checked the return values of all those external executions. You're assuming they succeed.

my $ret = system "`xcopy "C:\\Program Files\\UltraVNC\\*.*" "\\\\$ip\\ +C\$\\Program Files\\UltraVNC\\*.*" /r/i/c/h/k/e/Y"; die "xcopy failed" if $ret; $ret = 0; ...

If you'd like to improve your code generally, here are a few tips (good on you for using strict and warnings, you've just saved yourself a handful of head hair):

open(DAT,">>$resultOutput") || die("Cannot Open File"); print DAT "Bad username or password on the following machines:\n";

Be careful using || when performing error checking. It's a better idea to use or. You'll get bitten by precedence if you do this:

open DAT, ">>$filename" || die "foo";

Because || has higher precedence than the function call or the comma operator, that won't die if the open fails. It's evaluated like this:

open DAT, (">>$filename" || die "foo");

... and ">>$filename" is never logically false.

Also: it's good to get into the habit of using lexical filehandles:

open(my $dat, ">>", $resultOutput") or die("Cannot Open File"); print $dat "Bad username or password on the following machines:\n";

... for reasons described on this Perl5Wiki page.


That that is is that that is not is not

In reply to Re: Net Use issues by missingthepoint
in thread Net Use issues by Lobus

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.