Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- PERL 4.0 Reference Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

     tr/SEARCHLIST/REPLACEMENTLIST/cds

     y/SEARCHLIST/REPLACEMENTLIST/cds

             Translates all occurrences of the  characters  found
             in  the search list with the corresponding character
             in the replacement list.  It returns the  number  of
             characters  replaced  or  deleted.   If no string is
             specified via the =~ or !~ operator, the  $_  string
             is  translated.   (The string specified with =~ must
             be a  scalar  variable,  an  array  element,  or  an
             assignment  to  one  of those, i.e. an lvalue.)  For
             sed devotees, y is provided as a synonym for tr.

             If the c modifier is specified, the SEARCHLIST char-
             acter  set  is  complemented.   If the d modifier is
             specified, any characters  specified  by  SEARCHLIST
             that  are  not found in REPLACEMENTLIST are deleted.
             (Note that this is slightly more flexible  than  the
             behavior  of some tr programs, which delete anything
             they find in the  SEARCHLIST,  period.)   If  the  s
             modifier  is specified, sequences of characters that
             were translated to the same character  are  squashed
             down to 1 instance of the character.

             If the d modifier was used, the  REPLACEMENTLIST  is
             always interpreted exactly as specified.  Otherwise,
             if the REPLACEMENTLIST is  shorter  than  the  SEAR-
             CHLIST, the final character is replicated till it is
             long enough.  If the REPLACEMENTLIST  is  null,  the
             SEARCHLIST is replicated.  This latter is useful for
             counting characters in a  class,  or  for  squashing
             character sequences in a class.

             Examples:

                 $ARGV[1] =~ y/A-Z/a-z/;   # canonicalize to lower case

                 $cnt = tr/*/*/;           # count the stars in $_

                 $cnt = tr/0-9//;          # count the digits in $_

                 tr/a-zA-Z//s;             # bookkeeper -> bokeper

                 ($HOST = $host) =~ tr/a-z/A-Z/;

                 y/a-zA-Z/ /cs;            # change non-alphas to single space

                 tr/\200-\377/\0-\177/;    # delete 8th bit

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson