>>>>> "RC" == Robert Citek <robert.ci...@gmail.com> writes:

  RC> How does one transliterate in perl using a negated character class?
  RC> For example, I have a string abcxyz and I would like to turn it into
  RC> abNNNz.  I've been able to do the following:

  RC> $ echo "abcxyz" | perl -plane '$_ =~ y/[abz]/N/ '
  RC> NNcxyN

  RC> so I figured negating would give me the negated set, but it doesn't:

  RC> $ echo "abcxyz" | perl -plane '$_ =~ y/[^abz]/N/ '
  RC> NNcxyN

  RC> I know I've done this before.  What am I overlooking?

you are making a classic newbie mistake. tr (the prefered name for the
y/// op) is NOT a regex and does not use regex syntax. it doesn't need
[] as it always is character oriented. so rtfm on it some more and you
will see how to negate its list of chars and that using [] is not only
not needed but can lead to buggy code (the [] are treated as any other
char and translated too).

uri

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to