Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

strange constants.pm warning

by misterperl (Monk)
on Aug 30, 2021 at 17:35 UTC ( #11136227=perlquestion: print w/replies, xml ) Need Help??

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

...using constants.pm 1.04, I keep hitting this in the else: "Constant name '$name' has unknown problems" , which can only happen if:
if ($name =~ /^_?[^\W_0-9]\w*\z/ and !$forbidden{$name}) {
is false. So, I set a break like this:
<DBG>b 52 $name !~ /^_?[^\W_0-9]\w*\z/
and sure enough, it broke there. (My name is simple, DB_ERROR.) That's when things got weird, at the break, I tried:
<DBG>x $name =~ /^_?[^\W_0-9]\w*\z/ 1
DB<4> x $name !~ /^_?[^\W_0-9]\w*\z/ 0 ''
..another mystery, how the HECK DID IT break there? I tried:
<DBG>b 52 ! $name =~ /^_?[^\W_0-9]\w*\z/
which looks logically the same as <code> $name !~ /^_?^\W_0-9\w*\z/ <code> but, now more weirdness, it no longer breaks there.

My spyder sense tells me this is due to some pragma/debugger weirdness, since I'm breaking in the pragma. But the issue is there is nothing wrong with my use statement, yet it throws that unknown error warning, and I was trying to see why.

Wisdom please?

Replies are listed 'Best First'.
Re: strange constants.pm warning
by Perlbotics (Bishop) on Aug 30, 2021 at 17:57 UTC

    How do you init $name? Like use constant name => 42?

    Then

    if ( name =~ /^_?[^\W_0-9]\w*\z/ and !$forbidden{ name() }) {
    might work? Conststant creates a sub witht the given name that returns the value.

      use constant DB_ERROR => "database error";
      I haven't tried to see if the sub actually gets created- Im just trying to figure out why this valid statement throws this unknown warning message.. AND to find out why the debuger break where apparently it shouldn't..

        Okay, misunderstanding. I thought this happens in your code but it is actually a line from the import() sub of constant.

        } else { # Catch-all - what did I miss? If you get this err +or, # please let me know what your constant's name was +. # Write to <rootbeer@redcat.com>. Thanks! warnings::warn("Constant name '$name' has unknown +problems"); }

        Your example works here. Perhaps some non-printable characters have sneaked in to your text file or there is a clash (other module or within your code) that uses the same constant? What happens if you change DB_ERROR to MY_DB_ERROR? No better ideas ATM, sorry.

Re: strange constants.pm warning
by misterperl (Monk) on Sep 01, 2021 at 12:56 UTC
    the sysadmin got us on v1.33 and no more warnings! TY for the comments guys. I'm still perplexed as to why the debugger broke on a false statement.

    Cheers!

      the sysadmin got us on v1.33

      I've just re-read your OP and noticed that you said you were using v1.04. That's more than 20 years old! It is rather impressive that you have been using it solidly for so long and only just now hit a problem.

      Anyway, glad the upgrade has fixed it for you. Perhaps maybe consider an audit of other key modules in use on your systems with a few to further upgrades? ;-)


      🦛

        actually - not me, my client is. They keep cloning old boxes and we end up with stuff like this sometimes. Thanks for the observation I had no idea it was THAT old! I'd love to do a CPAN update on all but the client only allows them selectively.
Re: strange constants.pm warning
by Anonymous Monk on Aug 31, 2021 at 15:19 UTC

    I take it from previous comments that you mean constant.pm, not constants.pm, which I can not find in Metacpan.

    According to corelist, constant 1.04 shipped with Perl 5.7.3. Metacpan does not list this version even on Backpan.

    If this is right, wisdom may be hard to come by.

      yes my inattention to detail - constant.pm
        I did request that the node admin update the constant.pm module. That may also solve this. TYVM

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11136227]
Approved by Bod
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2021-12-05 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (31 votes). Check out past polls.

    Notices?