in reply to "Can't happen" bugs

if (grep { /^(dualvar|set_prototype)$/ } @_ ) { require Carp; Carp::croak("$1 is only avaliable with the XS version"); }
this code is wrong because it uses $1 not immediately after obtaining it. require Carp is probably overwriting it (it's a global var, after all, overwritten in every capturing regexp), and indeed the error message I was getting (" is only avaliable") can be explained by a failed match or an empty capture.
Nope. require Carp can't overwrite a different scope's $1. Even if (grep { /(...)/ } "abc") {print ":$1:"} has $1 undefined.

$1 is not "global", it is automatically dynamically scoped.

The problem is that the code is using $1 outside the scope in which it was set (the grep block). The code as written will never use the $1 from the match.

Replies are listed 'Best First'.
Re^2: "Can't happen" bugs
by gaal (Parson) on Jan 16, 2007 at 19:00 UTC
    You're right; I've since realized that what this code should do is

    if (my @bad = grep { /^(dualvar|set_prototype)$/ } @_ ) { ... }

    And then give @bad in the error message. (This'll give a bogusly redundant list if the import spec of Scalar::Util contains bogus redundancies, but I doubt that's a problem.)

    Anyway there's now a bug in the RT queue for this distro with the correct fix in it.