Path: utzoo!attcan!uunet!mcsun!ukc!edcastle!lfcs!ajcd From: ajcd@lfcs.ed.ac.uk (Angus Duggan) Newsgroups: comp.lang.perl Subject: Strange behaviour with | & ^ and associative arrays Summary: perl bug when mixing bitwise operators and associative arrays Keywords: perl, associative arrays, bitwise operators Message-ID: <2957@castle.ed.ac.uk> Date: 21 Mar 90 12:13:59 GMT Reply-To: ajcd@lfcs.ed.ac.uk (Angus Duggan) Organization: Laboratory for the Foundations of Computer Science, University of Edinburgh Lines: 42 I've come across a problem which occurs when mixing bitwise operators with associative array components; if the numeric value of an associative array component is negative, it is converted to zero when the expression is evaluated. The same thing does *not* happen for other arithmetic operators. This also affects the bitwise assignment operators |=, &=, and ^= (I think; last two untested). Try the script: #!/usr/local/bin/perl $fonts{"cmr10",300} = 1; # Correct values printed by following statement print STDOUT "Values are ", $fonts{"cmr10",300}, ",", $fonts{"cmr10",300} - 0, ",", $fonts{"cmr10",300} & 1, ",", $fonts{"cmr10",300} | 0, "\n"; $fonts{"cmr10",300} = -1; # Incorrect values printed by following statement print STDOUT "Values are ", $fonts{"cmr10",300}, ",", $fonts{"cmr10",300} - 0, ",", $fonts{"cmr10",300} & 1, ",", $fonts{"cmr10",300} | 0, "\n"; The output of this script is: Values are 1,1,1,1 Values are -1,-1,0,0 The second line should read: Values are -1,-1,1,-1 perl -v prints: $Header: perly.c,v 3.0.1.4 90/02/28 18:06:41 lwall Locked $ Patch level: 15 This is being run on a Sun 3/50 with SunOS 4.0.? In the instance in which it occurred, I can use || instead of |, but I'd prefer not to. Anyone other workarounds welcome. Angus == Angus Duggan, Department of Computer Science, | #include University of Edinburgh, JCMB, | USENET: ajcd@lfcs.ed.ac.uk The King's Buildings, Mayfield Road, | JANET: ajcd@uk.ac.ed.lfcs