Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Mystics always hope that science will some day overtake them. -- Booth Tarkington


devel / comp.lang.perl.misc / Re: multiway conditionals

SubjectAuthor
* multiway conditionalsRainer Weikusat
`* Re: multiway conditionalsPopping Mad
 `- Re: multiway conditionalsRainer Weikusat

1
multiway conditionals

<875y6rfqxk.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=382&group=comp.lang.perl.misc#382

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: multiway conditionals
Date: Mon, 10 Jul 2023 21:32:39 +0100
Lines: 43
Message-ID: <875y6rfqxk.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net iIkA7bF8vfSCdz+/3qoP7QeSLvotT3AWVoKa2G1VkteoxVyEs=
Cancel-Lock: sha1:XLX3OX4en9mrSEYVftF8vr1xM5A= sha1:FWYZRcvCneyNhVZWzbhOkNB3nWg= sha256:cLe6BJtJfQl4QxR2hfVzf1Nz97wDFBADi0Dm/Ef7WcA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Mon, 10 Jul 2023 20:32 UTC

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]

Re: multiway conditionals

<u8npn1$nb7$1@reader2.panix.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=383&group=comp.lang.perl.misc#383

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www.mrbrklyn.com!not-for-mail
From: rainbow@colition.gov (Popping Mad)
Newsgroups: comp.lang.perl.misc
Subject: Re: multiway conditionals
Date: Wed, 12 Jul 2023 23:05:18 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <u8npn1$nb7$1@reader2.panix.com>
References: <875y6rfqxk.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 13 Jul 2023 03:06:09 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="www.mrbrklyn.com:96.57.23.83";
logging-data="23911"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Content-Language: en-US
In-Reply-To: <875y6rfqxk.fsf@doppelsaurus.mobileactivedefense.com>
 by: Popping Mad - Thu, 13 Jul 2023 03:05 UTC

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?

Re: multiway conditionals

<877cqzhbhq.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=386&group=comp.lang.perl.misc#386

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: Re: multiway conditionals
Date: Sun, 16 Jul 2023 21:01:21 +0100
Lines: 51
Message-ID: <877cqzhbhq.fsf@doppelsaurus.mobileactivedefense.com>
References: <875y6rfqxk.fsf@doppelsaurus.mobileactivedefense.com>
<u8npn1$nb7$1@reader2.panix.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net oDB6k/J2cY+cLVm8LDf57gnOQO6b8I23xFguAwWDpYKusRtvQ=
Cancel-Lock: sha1:/udEPpImYH3pbaTjmpb1y4nY6Do= sha1:fUet86bNRi6eGTuPosJNgXMeSok= sha256:Ynbr6ceYkBmydDKQKt2NYRJoJbX5GPmqS8LAr0QU3NI=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Sun, 16 Jul 2023 20:01 UTC

Popping Mad <rainbow@colition.gov> 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.


devel / comp.lang.perl.misc / Re: multiway conditionals

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor