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

Two questions here; one, is it appropriate to place error handling in a subroutine; two, where am I going wrong in the last two 'elsif' statements in this thread?

sub errhand { if ($website eq "three"){ next; } elsif ($website eq "five"){ next; } elsif ($website eq "calnet-test"){ next; } #elsif ($old_ip eq /\d\d.\d\d.\d\d\d){ #next; #} #elsif ($new_ip eq /\d\d.\d\d.\d\d\d){ #next; #} else{ die, "ERROR - Format is 'deploy website old_ip new_ip || 'depl +oy [three; five;calnet-test] 21.01.001 22.02.002'" } }

Replies are listed 'Best First'.
Re: Is it appropriate to handle errors through a subroutine?
by roboticus (Chancellor) on Jan 02, 2014 at 04:27 UTC

    smturner1:

    Putting error handling code in a subroutine is fine, and can help reduce code replication.

    The last two elsifs aren't matching because $old_ip and $new_ip aren't equal to regular expressions--they're (presumably) strings. If you change the 'eq' into '=~' though, the code will see if the $old_ip and $new_ip match those regular expressions. ;^)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Is it appropriate to handle errors through a subroutine?
by kcott (Archbishop) on Jan 02, 2014 at 05:39 UTC
Re: Is it appropriate to handle errors through a subroutine?
by Anonymous Monk on Jan 02, 2014 at 15:17 UTC
    It is clear enough, therefore it will work. Also consider a series of statements (in a subroutine as before) ...

    return if ($website eq ...);
    return if ($new_ip ~= ...);
    ...
    die( ...);