[Israel.pm] Perl Advocacy

Offer Kaye offer.kaye at gmail.com
Mon Dec 27 07:50:31 PST 2004


On Mon, 27 Dec 2004 16:31:26 +0200, david istermann <interdist at gmail.com> wrote:
> What bugs me most is that in Perl there is no equivalent for PHP's str_replace:
> 
> $newstr = str_replace( array('<', '>', '&'), array('&lt;', '&gt;',
> '&amp;'), $oldstr);
> 

my %repl = (
          '&' => '&amp;',
          '>' => '&gt;',
          '<' => '&lt;'
        );
(my $newstr = $oldstr) =~ s/(<|>|&)/$repl{$1}/g;

I leave wrapping this in a subroutine called str_replace that builds
%repl and the right side of the s/// operator as a (trivial) excercise
for the reader...
Point is, I agree with the point brought up in the pages critisizing
PHP - having over 3000 functions, versus Perl's ~200, doesn't make it
into a richer or better language... on the contrary, IMO.

> Worse than that there is no trim that would remove spaces from the
> beginning and the end of a string.

I didn't understand this, Gabor. Please explain.

-- 
Offer Kaye



More information about the Perl mailing list