Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Perl on OSX > Re: tr question...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 12 Topic 1019 of 1075
Post > Topic >>

Re: tr question (probably wrong list to ask, but ...)

by chas.owens@[EMAIL PROTECTED] (Chas. Owens) Nov 30, 2007 at 09:29 PM

On Nov 30, 2007 9:19 PM, Doug McNutt <douglist@[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 ****ft-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/'
 




 12 Posts in Topic:
tr question (probably wrong list to ask, but ...)
joel_rees@[EMAIL PROTECTE  2007-12-01 09:33:12 
Re: tr question (probably wrong list to ask, but ...)
andy@[EMAIL PROTECTED] (  2007-12-01 01:56:44 
Re: tr question (probably wrong list to ask, but ...)
douglist@[EMAIL PROTECTED  2007-11-30 19:19:07 
Re: tr question (probably wrong list to ask, but ...)
chas.owens@[EMAIL PROTECT  2007-11-30 21:02:41 
Re: tr question (probably wrong list to ask, but ...)
chas.owens@[EMAIL PROTECT  2007-11-30 21:29:29 
Re: tr question (probably wrong list to ask, but ...)
douglist@[EMAIL PROTECTED  2007-11-30 20:18:12 
Re: tr question (probably wrong list to ask, but ...)
joel_rees@[EMAIL PROTECTE  2007-12-01 11:43:58 
interaction between tr and s (was Re: tr question -- probably wr
joel_rees@[EMAIL PROTECTE  2007-12-01 17:03:23 
Re: interaction between tr and s (was Re: tr question -- probabl
douglist@[EMAIL PROTECTED  2007-12-01 11:59:12 
Re: interaction between tr and s (was Re: tr question -- probabl
joel_rees@[EMAIL PROTECTE  2007-12-03 18:41:33 
Re: tr question (probably wrong list to ask, but ...)
chas.owens@[EMAIL PROTECT  2007-11-30 22:04:08 
Okay, it's not tr after all.
joel_rees@[EMAIL PROTECTE  2007-12-01 12:27:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 19:10:52 CDT 2008.