|
|
| XP is just a number | |
| PerlMonks |
Question regarding handling exceptions in subroutineby walkingthecow (Friar) |
| on May 12, 2013 at 08:29 UTC ( [id://1033176]=perlquestion: print w/replies, xml ) | Need Help?? |
|
walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
My script runs a command on a Linux system. For example:
Now, in my subroutine I want to run useradd $login and grab the output from the system. If the output is an error (e.g., user already exists), I want to return something like, "ERROR: $login already exists\n", or "ERROR: $login is not a valid UNIX username\n"... If it worked, it should return something like, "SUCCESS: $login added to system" Currently I am croaking if it's not a success, but that destroys my while loop. Basically, what's the best way to return an error message from a subroutine, and a success message if it succeeds? I've read the following:http://www.perlmonks.org/?node_id=113166 http://www.perl.com/pub/2002/11/14/exception.html While interesting, I know Perl has changed a lot in the past few years, so trying to get an updated opinion on the matter. Thanks!
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||||||||||