develooper Front page | perl.fwp | Postings from March 2012

Re: The sperm secret operator: is it new?

Thread Previous | Thread Next
March 14, 2012 15:50
Re: The sperm secret operator: is it new?
Message ID:
On Wed, Mar 14, 2012 at 01:46:34PM -0700, Andrew Savige wrote:
> > [ ~~ vs. scalar ]
> The ~~ secret operator is old hat, good ol' inchworm:
> BooK's innovation is to add <> and <>+0 to the end of it.
> BTW, in addition to inchworm-on-a-stick ~- to subtract one,
> I often use the converse -~ to add one (though only in Ruby
> and Python, not usually Perl). For example, -~1 produces 2
> in Ruby and Python, but -4,294,967,294 in Perl.

It works in C too. I was doing some research on secret operators today,
and I discovered the effects of the other inchworm-on-a-stick, and the
fact that both operators are broken for half the integers in Perl.

~- only decrements integers greater than 0 in Perl.
-~ only increments integers lesser than 0 in Perl.

According to Abigail and rgs, it's probably because ~ must also handle
strings. Abigail and I looked at the source of pp_negate, and it seems
like it does the right thing, so ~ seems to be the culprit. (I see that
tzchak Scott-Thoennes has provided a thorough answer in another mail.)

Frankly, I think this could be considered a bug. Both the left-facing
and right-facing versions of the inchworm on a stick should work on
all integers in Perl. Complement two arithmetics demand it! Now, the
question is, how long has this been broken in Perl? Forever?

 Philippe Bruhat (BooK)

 The learned man makes a mistake but once... but the truly stupid keep
 practicing until they get it right.
                                    (Moral from Groo The Wanderer #75 (Epic))

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About