in reply to Re: Range of chars except one
in thread Range of chars except one
This can be made even simpler. Remember that if a character is listed in a tr/// searchlist more than once, only the first occurance is meaningful. This means you can do something like:
It's (IMHO) cleaner and easier to read.
It's easier to modify, e.g. to exempt additional characters from being deleted.
It doesn't care what character is used for newline on the current platform. For example, I seem to remember that \n and \r have their meanings reversed on one platform (Macintosh?) because the platform standard is to use CR for line breaks.
</NL>
(Note I'm using octal here). This specifies that the newline character is replaced by itself, while everything else in that range is deleted.$string =~ tr/\n\000-\037/\n/d;
There are three advantages to this method: <NL>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Range of chars except one
by Anonymous Monk on Jan 21, 2002 at 08:47 UTC |
In Section
Seekers of Perl Wisdom