Re: The sperm secret operator: is it new?
[email protected] (Yitzchak Scott-Thoennes) Wed, 14 Mar 2012 14:57:09 -0700
| Newsgroups | perl.fwp |
|---|---|
| Message-ID | <CAN7g7HVEm9mP0+jSojSN4M+atgHuJaqt+COOf20vkVdUvB6tWA@mail.gmail.com> |
On Wed, Mar 14, 2012 at 7:48 AM, John Douglas Porter <[email protected]> wrote: > So is that the Perl 6 smart match operator? or something else? The latter. > In any case... How does it work here? =A0It looks like it's functionally > equivalent to scalar()... but why? Perl's ~ is operand sensitive; if its operand has a numeric value (either because it was assigned a number, the result of a numeric operation, or had been used in numeric context), it is a numeric bitwise or (implicitly converting to UV, or under the scope of use integer, IV, first); otherwise it is a string bitwise or. For most inputs, in either case it can be repeated to reproduce the original value and acts just like scalar(). Examples of exceptions: # floating point $x =3D 1.23; print ~~$x; # 1 # string used in numeric context $x =3D "1.23"; print ~~$x if $x !=3D 0; # 1 # integer out of range use Config '%Config'; $x=3D2**(8*$Config{uvsize}); print ~~$x; # max uv $x =3D -1; print ~~$x; # max uv $x =3D 2**(8*$Config{uvsize}-1); use integer; print ~~$x; # min iv $x =3D -2**(8*$Config{uvsize}-1)-1; use integer; print ~~$x; # min iv