greenhorn has asked for the wisdom of the Perl Monks concerning the following question:
<KBD>tr/,()@+~#$%^&*-{}[]<>\/\|//s;</KBD>
It worked, sort of. But it would change a string such as<KBD> Mississippi </KBD>into<KBD> Misisipi</KBD>.
??? Then it occurred to me that perhaps the presence of the hyphen within the search-list might be making Perl "think" I'd asked for a range. This seemed pretty far-fetched, but I decided I should check the result of escaping the hyphen:
<KBD>tr/,()@+~#$%^&*\-{}[]<>\/\|//s;</KBD>
To my surprise, it worked; punctuation marks were "squashed" as I'd wanted. Repeated alphanumeric characters were left untouched. Moving the hyphen to the very end of the search-list also stopped the unwanted removal of alphanumeric characters.
Why did the hyphen as first used have that effect, when no range resembling<KBD> A-Z </KBD>or<KBD> a-z </KBD>seems to have specified?
As ever, thanks in advance . . .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question concerning tr//
by ColtsFoot (Chaplain) on Aug 05, 2000 at 11:33 UTC | |
|
Re: Question concerning
by btrott (Parson) on Aug 05, 2000 at 03:07 UTC | |
|
Re: Question concerning tr//
by greenhorn (Sexton) on Aug 05, 2000 at 11:39 UTC | |
|
Re: Question concerning 'tr///'
by greenhorn (Sexton) on Aug 05, 2000 at 03:07 UTC | |
by ybiC (Prior) on Aug 05, 2000 at 03:22 UTC |