in reply to Subroutines within if statements

OT, but, your exit 0; may leave users -- those who enter "rm" for example -- believing your script failed. Better to tell them what went wrong, now that above responders have provided direct answers to your OP.

It may be well to insert something like line 2 (below):

else { print "Invalid response: use ONLY one of the following add, a, rem +ove, r\n"; exit 0; }

Test your opens, regex captures and the like before using them; TELL your users (or at least, give them a hint) how they screwed up.

Replies are listed 'Best First'.
Re^2: somewhat OT: Subroutines within if statements
by Joost (Canon) on Feb 21, 2008 at 22:50 UTC
    In fact you probably shouldn't use exit 0 for an error at all. Better to use die $message instead.

    Giving a non-zero exit code (as die() does) on error makes combining scripts in shell scripts / one-liners a lot easier:

    my-shell$ check-this-config-file.pl && then-stop-this-server && then-d +o-a-lot-of-stuff.pl && then-start-that-server
    And yes I do this a lot.