In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > > I know I'm missing something here, but this code just looks to me like I > shloud be doing it a better way.. > > Any ideas? > > > # -N > print "Number of Hosts? "; > # get user input and strip off "CR-LF" > chomp($n=<>); > $intel_num_hosts = join (" ", "-N",$n); > # if user did not enter a value, dont put the "-N" in > if ($n eq ""){ $intel_num_hosts = ""} > > # -n > print "Number of processes? "; > chomp($n=<>); > $intel_num_procs = join (" ", "-n",$n); > if ($n eq ""){ $intel_num_procs = ""}
Here's my version (corrections, improvements welcome); it's longer (not sure that's what you wanted), but it does a little error-checking... my $intel_num_hosts = ''; my $num_hosts = get_input("Number of hosts? "); $intel_num_hosts = join (" ", "-N", $num_hosts) if $num_hosts; my $intel_num_procs = ''; my $num_procs = get_input("Number of processes? "); $intel_num_procs = join (" ", "-n", $num_procs) if $num_procs; sub get_input { my $prompt = shift; my $input =''; my $err_cnt = 0; { print $prompt; chomp($input = <STDIN>); unless ($input =~ /^[^\D]+/ or $input eq '') { die "Invalid input, exiting\n" if ++$err_cnt > 2; redo; } } return $input; } -K -- Kevin Pfeiffer International University Bremen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]