develooper Front page | perl.perl5.porters | Postings from March 2022

Re: Pre-RFC: builtin:: functions for detecting numbers vs strings

Thread Previous | Thread Next
From:
Dagfinn Ilmari Mannsåker
Date:
March 9, 2022 15:16
Subject:
Re: Pre-RFC: builtin:: functions for detecting numbers vs strings
Message ID:
87o82frwaq.fsf@wibble.ilmari.org
demerphq <demerphq@gmail.com> writes:

> Perl defines that "7" and 7 are both equivalent in almost every
> regard, the few places they might not be the dev is expected to
> disambiguate, eg logical operators like ^ | & care, nothing else in

These are bitwise operators, not logical, and are an anomalous exception
to the usual rule in perl that the operator decides what to treat the
operand as.

> perl does, and in those cases the dev should be specifying which
> behavior they want by doing 0+$x | 0+$y or "$x" | "$y". Because to
> perl both "are" the number seven and both "are" the string "7".

To remedy this anomaly, the 'bitwise' feature was introduced in 5.22 and
and added the :5.28 and later feature bundles. It makes the plain
bitwise operators consistently treat their arguments as integers, and
adds dotted variants (&. |. ^. ~.) that treat the arguments as strings.

https://metacpan.org/pod/feature#The-'bitwise'-feature

> cheers,
> Yves

- ilmari

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About