Popping Mad <
[email protected]> writes:
On 7/10/23 16:32, Rainer Weikusat wrote:
Perl 38 came with the announcement that the P5P have unfortunately not
managed to get rid of the intellectual miscarriage named smartmatching
and have therefore - at least that's how I understood the announcement -
decided to throw the useful bit of that (the given/ when syntax) under a
bus to avoid admitting that this DWNEWEHS-operator (Do What Nobody Else
Would Ever Have Suspected) was a stupid idea.
This reopens the question how to do multiway conditionals in perl. An
IMHO sane way would be: Define two subroutines,
sub matches
{
for my $x (@_) {
return 1 if $_ == $x;
}
return;
}
sub str_matches
{
for my $x (@_) {
return 1 if $_ eq $x;
}
return;
}
which can then be used as follows
for ($! + 0) {
matches(EINPROGRESS)
and return NBFH_WANT_WRITE;
matches(EACCES, EADDRNOTAVAIL, EAGAIN, ECONNREFUSED,
ECONNRESET, ENETDOWN, ENETUNREACH, EPERM,
ETIMEDOUT)
and return NBFH_ERR;
sys_die('connect');
}
[str_matches to be used for string matching]
what is wrong with if?
It's not a multiway conditional, ie, one which evaluates an expression
once and then provides a way to test the result for multiple values or
sets of values.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)