On 12-Aug-06, at 11:19 PM, snacktime wrote:

>> Have you tried the seemingly simple approach like this, which avoids
>> eval:
>>
>> ratdog:~ mike$ irb --prompt simple
>>  >> @upper_case = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>> => "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>>  >> def uc(s)
>>  >> s.tr('abcdefghijklmnopqrstuvwxyz', @upper_case)
>>  >> end
>> => nil
>>  >> uc('banana')
>> => "BANANA"
>>  >> @upper_case = 'abcdefghijklmnopqrstuvwxyz'
>> => "abcdefghijklmnopqrstuvwxyz"
>>  >> uc('banana')
>> => "banana"
>
> Yes I tried it without eval also, but it won't produce the same output
> as the perl code.   I've tried every incantation I can think of but no
> luck.  I'm checking my results by comparing them to the output of
> perl's String::Parity.  The perl code  I posted is basically an
> abbreviation of what String::Parity does when setting even parity.
> It's the last bit in this damn module I'm working on also:)  If I get
> this figured out I'll be done.

Can you give me a hint as to what doesn't work?  For a simple upper  
case subset of your code (using double quotes) I see

ratdog:~ mike$ irb --prompt simple
 >> @even_parity = "AB\303D\305\306GH\311\312K\314MN\317P\321\322S 
\324UV\327\330YZ"
=> "AB\303D\305\306GH\311\312K\314MN\317P\321\322S\324UV\327\330YZ"
 >> @even_parity.length
=> 26
 >> def setEvenParity(s)
 >> s.tr('A-Z', @even_parity)
 >> end
=> nil
 >> setEvenParity('ABACAB')
=> "ABA\303AB"

seems pretty reasonable - can you show a simple example of what  
doesn't behave as you want?

Hmm, thinking about it, when you do the Ruby eval, are uou missing  
quotes around @even_parity?

Mike

-- 

Mike Stok <mike / stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.