http://qs321.pair.com?node_id=672660

blahblahblah has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to port a bit of old C code to perl. I generated a ton of test cases from the C program output, wrote my Perl code, and then compared the results for the same inputs. Some cases are successful; others are not. I put in a bunch of debugging and fixed some simple things -- incorrect array indexes; for loops translated wrong; etc. -- but I'm hung up on something I can't figure out. Here is the C code:
return (func(token4) & 95) | (func(token5) & 32 | func(token5) & 128); /* "func" is defined as: */ unsigned long func (c) unsigned char *c;
In my failing case, the values of token4 & token5 are 0 and 32, resulting in:
(0 & 95) | (32 & 32) | (32 & 128)
The C code evaluates this to a result of zero. I tried porting the same to perl, and for some of my test cases it matches the C result, but for this particular case the following perl code prints 32:
perl -e 'print ((0 & 95) | (32 & 32) | (32 & 128))'
I read perlop but didn't find anything meaningful to me. It seems from Will/Can Perl 6 clean up the bit-wise operator precedence mess? that Perl tries to have the same operator precedence as C. Do I need to pack my data into something other than a plain old scalar? I'm not well versed in C or in this sort of bitwise manipulation in Perl. Can anyone spot an obvious problem or offer some pointers?

Thanks,
Joe