"Owen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Wed, 28 Apr 2004 10:42:01 +0530
> "Sumanth Sharma" <[EMAIL PROTECTED]> wrote:
>
> >         Can you help me figure out why need tr/// when you have s/// and
> > Vice versa ( NO, s/// is more powerful?).
>
> Well I would say that the way they operate is different.
>
> tr/// looks at each character and replaces it
>
> eg, tr/aeiou/-/ replaces all vowels with a -
>
> s/// looks for a pattern and replaces that pattern
>
> eg s/aeiou/-/ replace any pattern of aeiou with a -
>
> Try this
>
> #!/usr/bin/perl -w
> use strict;
>
> my $word='aeiou';
> $word =~tr/aeiou/-/;
> print "translated word is $word\n";
>
> $word='aeiou';
##> $word =~s/aeiou/-/;
but ..... $word =~ s/[aeiou]/-/g; ## will achieve the same thing.

Anyway, is it true that "tr/aeiou/-/" is faster than "s/[aeiou]/-/g" ?.



Thanks in Advance,
Sumanth Sharma



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to