Perl, PHP and Sour Grapes?
Search CPAN (Perls repository of re-usable modules) for “PHP” and you might be surprised by the results.
For example PHP::Strings. What’s interesting about this module is it partly implements PHP’s string functions in Perl, or tells you where to look for more info.
The following code, for example;
use PHP::Strings qw( :trim );
my $word = " Hello World! ";
$word = trim($word);
Results in the following message;
<:strings::trim will not be implemented>.
…and refers you to the Perl FAQ on How do I strip blank space from the beginning/end of a string?. Nice stuff if you’re a PHP coder hacking away in Perl.
What’s not so nice is the related reading which links to a virtual web ring of “I hate PHP” rants. Trawling through the list, there are some valid technical points against PHP but largely mixed with misconceptions resulting from common “gotchas” that afflict Perl coders, when getting started with PHP. Although emphasis is technical comparison, the impression is that there’s some, more profound (irrational?) reason why (some) Perl coders feel the need to take a shot at PHP.
It’s tempting to suggest that some feel PHP stole Perl’s “rightful place” as the #1 web language. “Sour grapes” in other words but perhaps that’s unfair.
May be it’s because (superficially) Perl and PHP look too similar (sibling rivalry etc.). These days don’t think that’s true though. PHP has distinguished itself as a specialized language for solving the “web problem” while Perl remains a powerful, general purpose language. And although PHP was originally Perl-inspired, Java seems to be a bigger factor in PHP’s current design.
Have to confess I’m not Perl’s biggest fan, although I’d choose it (or better yet, Python) over PHP for tasks like batch processing and networking.
To me Perl offers too many opportunities to write unreadable code. The trim() function, that PHP::Strings refuses to implement, highlights the issue. What makes more sense (to a human being)?
$string = trim($string);
$string =~ s/^s+//;
$string =~ s/s+$//;
But that’s just my own preference.
Anyway, in the end holy wars lead nowhere. More useful is this issue of the Perl Review, which does an excellent, side by side, comparison of Perl and PHP which makes a good starting point if you know one and need to work with the other.