Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: backslash found where operator expected at

by perlfan (Vicar)
on Apr 22, 2021 at 05:32 UTC ( [id://11131573]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found