On Nov 30, 2007 9:19 PM, Doug McNutt <[EMAIL PROTECTED]> wrote:
> At 01:56 +0000 12/1/07, Andy Holyer wrote:
> >On 1 Dec 2007, at 00:33, Joel Rees wrote:
> >
> >>This is probably the wrong list for this question, but is anyone  willing 
> >>to give me a clue why
> >>
> >>$line =~ tr/+/ /;
> >>
> >>would clip out the lead bytes of a shift-JIS string in a cgi script?
> >>
> >what was just expressed", but you haven't expressed anything so far,  so god 
> >knows what it will match.
> >
> >I think you meant to say ".+", but that will just delete the whole  string 
> >in this context. What did you want to do?
>
> + is a special representation of a space in URL encoding but it's the 
> one-or-more collective char in perl.  My guess is that the intent is to 
> replace plus's with spaces which requires escaping the +, How about
>
> $line =~ tr/\+/ /g;
>
> where I have added the g to get them all.
>
> But what the devil is the thingy (missing char) repeated at least once? 
> Should it not have produced a compile error or a least a warning?  Was the -w 
> switch used?
>
> --
> --> On the eighth day, about 6 kiloyears ago, the Lord realized that free 
> will would make man ask what existed before the Creation. So He installed a 
> few gigayears of history complete with a big bang and a fossilized record of 
> evolution. <--
>

The tr/// operator does not take a regex, it takes two strings.  It
performs a transliteration of items (based on the options passed to
it) of the characters in first string into the characters in the
second string on the scalar it is bound to.  The only special
characters are '-' between two characters (creates a range) and
backslash (escapes for '-' and the normal escape characters like \n,
\t, etc.).

perl -le '$_="this+is+a+string";tr/+/ /;print'

Thus you can create a quick ROT13 like this:

perl -pe 'tr/a-zA-Z/n-za-mN-ZA-M/'

Reply via email to