in reply to Re: backslash found where operator expected at
in thread backslash found where operator expected at

In the spirit of TIMTOWTDI:
my $handles = { 400 => 1, # BAD_INPUT 403 => 31, # SERVICE_ACCESS_ERROR 500 => 32, # SERVICE_EXECUTION_ERROR 503 => 30, # SERVICE_ERROR }; for ($response_code) { if ($_ == 200) { # OK print_response $response_content; exit 0; }; if (defined $handles->{$_}) { exit $handles->{$_}; } }
$handles could also be a CODE refs that do something, then exit:
my $handles = { 200 => sub { print_response $response_content; 0}, # OK! 400 => sub { 1}, # BAD_INPUT 403 => sub {31}, # SERVICE_ACCESS +_ERROR 500 => sub {32}, # SERVICE_EXECUT +ION_ERROR 503 => sub {30}, # SERVICE_ERROR }; for ($response_code) { if (defined $handles->{$_}) { # check for 'CODE' ref up to you exit $handles->{$_}->(); } }

Replies are listed 'Best First'.
Re^3: backslash found where operator expected at
by ikegami (Patriarch) on Apr 30, 2021 at 03:18 UTC

    I love dispatch tables. Definitely something to consider in such situations. I simply didn't think them particularly clear/clean/useful here.

    Seeking work! You can reach me at ikegami@adaelis.com