Re: tr question (probably wrong list to ask, but ...)
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? That's a badly-formed regular expression. + means one or more of 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?
Okay, it's not tr after all.
On 平成 19/12/01, at 12:04, Chas. Owens wrote: On Nov 30, 2007 9:43 PM, Joel Rees [EMAIL PROTECTED] wrote: I guess it would help if I posted my code and what it puts out. snip Whoa, way to much information. :-) Try to reproduce your issue with the least amount of code and data. Actually, after cleaning out some of the extraneous stuff, I can see it is not tr/// doing the dirty deed after all (which is a relief, in a way): chatter_0 this+is+a+test.+%82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82% B7%81B chatter_tr1 this is a test. %82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82% B7%81B chatter_tr this is a test. アヘeXgナキB chatter this+is+a+test.+これはテストです。 Even though stripping the '+' out forces what had been intermittent behavior, I can see that tr/// is doing its job right. Off hand I would say your problem is probably with the encoding of your data (and Perl's lack of knowledge about it). Try using the locale or encoding pragmas. Yeah, I'll have to go back to that black magic. Thanks everybody for being listening ears. Joel Rees (waiting for a 3+GHz ARM processor to come out, to test Steve's willingness to switch again.)
Re: tr question (probably wrong list to ask, but ...)
At 21:29 -0500 11/30/07, Chas. Owens wrote: The tr/// operator does not take a regex, it takes two strings. Yep. Damn. What I meant to type is $line =~ s/\+/ /g; But that does explain why there was no error message. Looking at Joel's code the substitute might still be the way to go. -- -- From the U S of A, the only socialist country that refuses to admit it. --
Re: tr question (probably wrong list to ask, but ...)
On Nov 30, 2007 9:43 PM, Joel Rees [EMAIL PROTECTED] wrote: I guess it would help if I posted my code and what it puts out. snip Whoa, way to much information. Try to reproduce your issue with the least amount of code and data. Off hand I would say your problem is probably with the encoding of your data (and Perl's lack of knowledge about it). Try using the locale or encoding pragmas.
Re: tr question (probably wrong list to ask, but ...)
I guess it would help if I posted my code and what it puts out. 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? Come to think of it, I think it's being applied while the string is still hex-encoded, so it makes even less sense to me. (I know, I should be letting the CGI module decode the url-encoded string. But I seem to be mis-understanding something fundamental here. Which is why a newbies list would probably be better for this question.) # The code that grabs the parameters: my $qString = $ENV{'QUERY_STRING'}; my @list = split( '', $qString, 10 ); my %queries = (); foreach my $pair ( @list ) { my ( $key, $value ) = split( '=', $pair, 2 ); # Really should just give in and use CGI. #$key =~ tr/+/ /; $key =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack (C, hex ($1))/eg; $queries{ $key . '_0' } = $value; my $value_y = my $value_tr = $value; $value_y =~ y/+/ /; $queries{ $key . '_y1' } = $value_y; $value_tr =~ tr/+/ /; $queries{ $key . '_tr1' } = $value_tr; $value_y =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack (C, hex ($1))/eg; $queries{ $key . '_y' } = $value_y; $value_tr =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack (C, hex ($1))/eg; $queries{ $key . '_tr' } = $value_tr; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack (C, hex ($1))/eg; $queries{ $key } = $value; } # For reference, the code being used to dump the parameters to html: sub dumpQueries { if ( $debugParams ) { print language = $language, function = $function\n; print table border='1'\n; my @keys = keys ( %queries ); foreach my $key ( @keys ) { my $value = $queries{ $key }; if ( !defined ( $value ) ) { $value = UNDEF; } print trtd align='right'$key/tdtd align='left'$value/ td/tr\n; } print /table\n; } } # results- chatter this+is+a+test.+これはテストです。 function_tr eキ chatter_y1 this is a test. %82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82%B7% 81B who_tr1 daddy function投稿する who_y1 daddy function_tr1%93%8A%8De%82%B7%82%E9 who daddy who_0 daddy who_tr daddy who_y daddy chatter_0 this+is+a+test.+%82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82%B7%81B chatter_y this is a test. アヘeXgナキB function_y eキ chatter_tr this is a test. アヘeXgナキB function_y1 %93%8A%8De%82%B7%82%E9 function_0 %93%8A%8De%82%B7%82%E9 chatter_tr1 this is a test. %82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82% B7%81B # results-sorted- chatter_0 this+is+a+test.+%82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82%B7%81B chatter_y1 this is a test. %82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82%B7% 81B chatter_tr1 this is a test. %82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82% B7%81B chatter_y this is a test. アヘeXgナキB chatter_tr this is a test. アヘeXgナキB chatter this+is+a+test.+これはテストです。 function_0 %93%8A%8De%82%B7%82%E9 function_y1 %93%8A%8De%82%B7%82%E9 function_tr1%93%8A%8De%82%B7%82%E9 function_y eキ function_tr eキ function投稿する who_0 daddy who_y1 daddy who_tr1 daddy who_y daddy who_tr daddy who daddy # results-html- language = j, function = talk table border='1' trtd align='right'chatter/tdtd align='left'this+is+a+test. +これはテストです。/td/tr trtd align='right'function_tr/tdtd align='left'eキ/td/ tr trtd align='right'chatter_y1/tdtd align='left'this is a test. %82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82%B7%81B/td/tr trtd align='right'who_tr1/tdtd align='left'daddy/td/tr trtd align='right'function/tdtd align='left'投稿する/ td/tr trtd align='right'who_y1/tdtd align='left'daddy/td/tr trtd align='right'function_tr1/tdtd align='left'%93%8A%8De%82% B7%82%E9/td/tr trtd align='right'who/tdtd align='left'daddy/td/tr trtd align='right'who_0/tdtd align='left'daddy/td/tr trtd align='right'who_tr/tdtd align='left'daddy/td/tr trtd align='right'who_y/tdtd align='left'daddy/td/tr trtd align='right'chatter_0/tdtd align='left'this+is+a+test.+% 82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82%B7%81B/td/tr trtd align='right'chatter_y/tdtd align='left'this is a test. アヘeXgナキB/td/tr trtd align='right'function_y/tdtd align='left'eキ/td/tr trtd align='right'chatter_tr/tdtd align='left'this is a test. アヘeXgナキB/td/tr trtd align='right'function_y1/tdtd align='left'%93%8A%8De%82% B7%82%E9/td/tr trtd align='right'function_0/tdtd align='left'%93%8A%8De%82% B7%82%E9/td/tr trtd align='right'chatter_tr1/tdtd align='left'this is a test. %82%B1%82%EA%82%CD%83e%83X%83g%82%C5%82%B7%81B/td/tr /table # results-extract- chatter this+is+a+test.+これはテストです。 chatter_tr this is a test. アヘeXgナキB function投稿する
Re: tr question (probably wrong list to ask, but ...)
At 01:56 + 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. --
Re: tr question (probably wrong list to ask, but ...)
On Nov 30, 2007 7:33 PM, Joel Rees [EMAIL PROTECTED] 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? snip The only thing that should do is replace occurrences of '+' with ' ' in $line. You can read more about the tr/// operator in perldoc perlop.
tr question (probably wrong list to ask, but ...)
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? Come to think of it, I think it's being applied while the string is still hex-encoded, so it makes even less sense to me. (I know, I should be letting the CGI module decode the url-encoded string. But I seem to be mis-understanding something fundamental here. Which is why a newbies list would probably be better for this question.) Joel Rees (waiting for a 3+GHz ARM processor to come out, to test Steve's willingness to switch again.)
Re: tr question (probably wrong list to ask, but ...)
On Nov 30, 2007 9:19 PM, Doug McNutt [EMAIL PROTECTED] wrote: At 01:56 + 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/'