in reply to Net Use issues

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

Replies are listed 'Best First'.
Re^2: Net Use issues
by Lobus (Initiate) on Feb 16, 2009 at 18:09 UTC
    Thank you for all of your help. I forgot to mention that I am rather new to using perl. The only part of your help that i am really having trouble with comprehending is:
    # 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 ...
    I do not understand how to correctly use the subroutines.