Comments below.
-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED]
Sent: Friday, August 25, 2006 6:25 PM
To: Perl Beginners
Subject: Re: Using a regular expression to remove all except
certaincharacters.
Dr.Ruud wrote:
<snip>
>>
>> You might actually be looking for this:
>>
>> (my $newstring = $oldstring) =~ tr/0-9A-Za-z/ /cds;
>>
>> which replaces runs of non-alphanumeric characters with a single
space.
John W. Krahn wrote:
> No it doesn't:
>
> $ perl -le' ( $_ = q[&[EMAIL PROTECTED] ) =~ tr/0-9A-Za-z/
/cds; print'
> ghjk76565hgfg
>
> You would have to use the substitution operator to replace runs of
> non-alphanumeric characters with a single space.
<snip>
Actually, you're both wrong. Just leave out the 'd' modifier, which is
deleting the replaced characters instead of squashing them.
>From the perldoc perlop manpage:
c Complement the SEARCHLIST.
d Delete found but unreplaced characters.
s Squash duplicate replaced characters.
...
tr/a-zA-Z/ /cs; # change non-alphas to single space
So the correct test would be:
perl -le' ( $_ = q[&[EMAIL PROTECTED] ) =~ tr/0-9A-Za-z/ /cs;
print'
which yields:
' ghjk 76565 hgfg'
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>