Skip to main content

Posts

Showing posts with the label Perl

"Inchworm on a Stick" in PHP

~- is known as the inchworm on a stick operator in Perl obfuscation circles. It isn't really an operator; it's a term coined to describe negating a value and then taking its compliment, the apparent effect of which is to decrement the value. (To understand why, you need to understand how negative numbers are represented in binary.) In Perl, ~- works for positive values: for ($i = 3; $i > -3; $i--) { print ~-$i . "\n"; } $ perl test.pl 2 1 0 4294967295 4294967294 4294967293 Interestingly enough, when the same is tried in PHP the results are slightly different... 2 1 0 -1 -2 -3 PHP treats the value as a signed integer where Perl treats it as an unsigned integer. I don't know which way is "better" or which is "more correct," but it is something I found interesting and I thought would be worth sharing.

PHP != Perl

People irk me when they expect PHP to behave like <insert your favorite language here>. Most recently, I ran across this blog entry Perl vs PHP: Variable Scoping via the help of PHPDeveloper.org . I'm sure Leonid is a great fellow and really smart... but he just happened to trip my irk-wire. The post is an innocent enough "here's a problem that I ran into, so I'll blog it in case someone else has the same issue." Reading between the lines though, I get the feeling his underlying belief is that because PHP and Perl are similar that they should have the same variable scoping rules, and that since PHP's doesn't correspond to Perl's that PHP is wrong and this should be documented as such. Each language is different. If PHP were so similar to Perl, it wouldn't be called PHP... it'd be called Perl. Or maybe a dialect, like PHPerl. I really wish people would stop comparing the two. Quite frankly, I don't see much similarity betwe...