walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
while ( my $user = <$fh> ) { chomp $user; my $out = $system->adduser( login => $user ); if ( $out =~ /something/ ) { do this; } }
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: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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question regarding handling exceptions in subroutine
by choroba (Cardinal) on May 12, 2013 at 10:05 UTC | |
by walkingthecow (Friar) on May 12, 2013 at 10:12 UTC | |
by moritz (Cardinal) on May 12, 2013 at 10:37 UTC | |
by space_monk (Chaplain) on May 12, 2013 at 11:28 UTC | |
by karlgoethebier (Abbot) on May 12, 2013 at 12:24 UTC | |
by space_monk (Chaplain) on May 13, 2013 at 10:28 UTC | |
| |
by karlgoethebier (Abbot) on May 12, 2013 at 12:23 UTC |