c has asked for the wisdom of the Perl Monks concerning the following question:

i am using getopt::long and have a couple of options that i would like to check on the values users pass along to them. for example, when i use 'upload=s' => \$upload, i'd like to limit what the string value being passed would be. so i wrote

if ($upload eq "run") { &copy_tftp_run; exit(0); } elsif ($upload eq "start") { &copy_tftp_start; exit(0); } elsif ($upload) { print "\nYour destination choice for Uploads does not appear to be v +alid.\n\n" ; exit(1); }

however, when i run the program with --upload and a value other than "run" or "start", i get an error dealing with the next for loop. i would have thought that the final elsif statement would test true for something like --upload dog causijg the error statement to print and the script to exit.

humbly -c

Replies are listed 'Best First'.
Re: using 'value=s' = \$value
by perrin (Chancellor) on Aug 23, 2001 at 22:17 UTC
    I think this would be better written as:
    for ($upload) { if (/^start$/) { &copy_tftp_start; } elsif (/^run$/) { &copy_tftp_run; } else { die "Your destination choice for Uploads does not appear to + be valid.\n" } }
Re: using 'value=s' = \$value
by Cine (Friar) on Aug 23, 2001 at 21:41 UTC
    You are currently returning a fault if the user actually writes something that evaluetes to true. Are you sure you just dont want a else case as the last?

    T I M T O W T D I
A reply falls below the community's threshold of quality. You may see it by logging in.