in reply to runtime problem; elusive error

A small clue: the nastiness is in, or is related to Readonly. If you can do without the read only stuff the code works as expected. If you instead:

use strict; use warnings; use constant DBG_ANY => -1; use constant DBG_INFO => 0x0004; use constant DBG_KEYS => 0x0008; use constant DBG_RAND => 0x0080; my @Vals = ( DBG_ANY, 1, 2, DBG_INFO, DBG_KEYS, ); my $_debug_ops = (DBG_RAND | DBG_KEYS | DBG_INFO); printf "debugops = 0x%04x\n",$_debug_ops;

it prints:

debugops = 0x008c

Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: runtime problem; elusive error
by grinder (Bishop) on Sep 20, 2007 at 14:31 UTC

    ooh, nice one.

    I shall bookmark this thread, so that I can point it out to people who have drunk the PBP Kool-aid™ and tout Readonly as the best thing since sliced bread (or at least better than constant). May they see the error of their ways :)

    • another intruder with the mooring in the heart of the Perl

Re^2: runtime problem; elusive error
by perl-diddler (Chaplain) on Sep 20, 2007 at 16:53 UTC
    Looks like the "workaround" would be (removing the @Vals) line, as that hides the errormy $_debug_ops = (0 | DBG_RAND | DBG_KEYS |DBG_INFO); That puts in numeric context...sigh. Sometimes I'd like to be able to put a "numeric" or "string" in front a var to let it know what I want. The alternative is use something of the appropriate type (num or string), first, but that's not nearly so clear as being able to put in a "numeric" , like one does with "scalar", now.

    Thanks for the heads up...I'd report it as a but, but not sure how they'd fix it -- though I sure don't know why it's returning "=28" (hex equiv to left paren).

    It's interesting that the XS version is consistent (i.e. same constant).

      though I sure don't know why it's returning "=28"

      That's the bitwise string-OR of the stringified decimal representations of the three values, i.e.

      "128" | "8" | "4"

      or, more eplicitly

      chr(ord('1') | ord('8') | ord('4')) . # '=' chr(ord('2') | ord('') | ord('') ) . # '2' chr(ord('8') | ord('') | ord('') ) # '8'

      I'd like to be able to put a "numeric" or "string" in front a var to let it know what I want

      You can. They are spelled "0+" and "''." respectively.

      my $x = '8'; my $y = '16'; print((0+$x) | (0+$y), "\n"); # 24 print((''.$x) | (''.$y), "\n"); # 96

      Update: Oops, that doesn't quite answer your question. If the variable wasn't read-only, you could do the following:

      $x .= ''; # Stringify $x += 0; # Numerify