in reply to Re: Re: Ugly syntax
in thread Ugly syntax

In a nutshell, this is what sucks about constant. It's not really a built-in, but rather more of a hack based on an implementation detail.

I used it on a big project, and I don't think I would do it again. The syntax for using constants in interpolated strings and HERE docs is horrible, and you have to be constantly alert for subtle bugs caused by the problem you desribe here. I think you're better off with globals.

Replies are listed 'Best First'.
Re: Re: Re: Re: Ugly syntax
by gav^ (Curate) on Dec 04, 2001 at 21:26 UTC
    Some of the mod_perl scripts I inherited used loads of constants. I think they suck because a) interpolation doesn't work properly and b) you get an annoying 'redefinition' warning under mod_perl first time you run the script

    I prefer using a stack of variables with all caps at the top of each script, for example:

    my $SMTP = 'blah'; my $EMAIL = 'blah@blah.com'

    All my other variables are all lower case, and while these aren't 'true' constants I don't ever modify them.

    Gav.

      You actually can make interpolation work, but it's ugly.

      ${[CONSTANT]}
      You shouldn't get redefinition warnings under mod_perl. Check the guide for information on what could be causing it.