develooper Front page | perl.perl5.porters | Postings from November 2001

Re: [ID 20011115.119] no warning for useless /d in tr/0-9//d

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
November 15, 2001 07:50
Subject:
Re: [ID 20011115.119] no warning for useless /d in tr/0-9//d
Message ID:
20011115104945.C270015@linguist.thayer.dartmouth.edu
On Thu, Nov 15, 2001 at 01:24:33PM +0000, sdouglas@arm.com wrote:

> [2a] perl could give a warning, e.g. "Useless use of /d in
> transliteration (tr///)", for the following:
>     perl -we 'my $x = "1x32141x98234"; $x =~ tr/x//d'

How is that a useless use of /d?


> (which then becomes case [1a]) and
> 
> After the /d is known to be useless it could allow
>     perl -we '"1x32141x98234" =~ tr/x//d'
> 
> [2b] (somewhat harder and probably not as useful)
>     perl -we 'my $x = "1x32141x98234"; $x =~ tr/a-z/l-za-m/d'
> The tr is useful but the /d isn't.

That's probably not very hard at all; simply count the number of characters
in each class, and if they're the same, the /d is useless.

There could also be a warning when the left side includes more characters
than the right side.


Of course, adding these warnings would probably affect a fair amount of
existing code.


Ronald

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About