[thelist] Perl vs PHP [hopefully not a relegious war]

shawn allen shawn at alterior.net
Thu Nov 14 16:52:01 CST 2002


quoth Richard Hall:
> >A client and I were having a small discussion about Perl and how it
> >compares with PHP, ASP and JSP middleware. We are doing this job with
> >Perl, and it seems to me its a real pain to do a lot of things that
> >are just super simple in PHP for example.

This could be said of just about every task in any language. Likewise,
most perl-heads probably find the syntax:

$foo = preg_replace('/foo/g', 'bar', $foo);

rediculously cumbersome in comparison to:

$foo =~ s/foo/bar/g;

And in perl, since there's no overhead involved in requiring the regular
expression engine, there's no need for the distinction between preg-,
ereg-, and str_replace(). One could go on all day...

> >Like we had to trim a field of blank characters, and in Perl you have
> >to regex it, in PHP you simply use the trim method.

trim() is actually a function.

> Then why not write a Perl script to Trim() and call it as needed.

That's a great idea. (Note that there are an infinite number of other
ways to write this):

sub trim {
    $_ = shift;
    s/^\s+//;
    s/\s+$//;
    return $_;
}

Now, in perl, you *could* call that a method if you really wanted to:

print main::trim($foo);

:)

--
shawn allen
  mailto://shawn@alterior.net
  phone://415.577.3961
  http://alterior.net
  aim://shawnpallen




More information about the thelist mailing list