Perl experts: what is this code doing?
Hello all,
I have translated a Perl module to Ruby and it went pretty well except for one little bit that I cannot figure out. Here is the Perl code: Code:
$info{'flags_raw'} = unpack('V', $self->_readAndIncrementOffset(4)); I have the identical Ruby code: Code:
flags_raw = readAndIncrementOffset(4).unpack("V")[0] So: I don't know Perl all that well, but there must be some of that trademark Perl voodoo going one here right? Can anyone tell me why the same operation (ie: a bitwise '&' and a ternary operator) are giving two different results for the same input? I must admit I do not know much about bitwise operations, so maybe the problem here is differences between how Ruby and Perl evaluate bitwise operations? Any insight appreciated. |
It seems to me that the Perl code does exactly what you expected it to do. It seems that the only difficulty is the Ruby code. From what you have told us, it seems that (2 & 0x0001) evaluates to true in Ruby; is this right? Can you verify this?
|
Quote:
I should have realized: It is evaluating to '0' which in ruby is considered true whereas in Perl it is false. So simple... |
All times are GMT -5. The time now is 09:04 AM. |