http://www.perlmonks.org?node_id=251677


in reply to Re: Re: Location of 'use' statements
in thread Location of 'use' statements

The problem with "use constant" is that the constants are implemented as subroutines. This means that they break (silently) if you try to use them as hash keys, in double-quoted strings, or any other place where barewords are not interpreted as sub calls.

If you use global variables instead, everyone knows what they are and you avoid these bugs which tend to catch every user of constant at least once.

  • Comment on Re: Re: Re: Location of 'use' statements

Replies are listed 'Best First'.
Re: Re: Re: Re: Location of 'use' statements
by demerphq (Chancellor) on Apr 19, 2003 at 17:41 UTC

    This means that they break (silently) if you try to use them as hash keys, in double-quoted strings, or any other place where barewords are not interpreted as sub calls.

    Hmm. *grin* I can't recall being bitten by those things. I've used constants for array indexes on occasion, but never hash indexes. But its good to keep in mind. Thanks.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...