in reply to Re: Ugly syntax
in thread Ugly syntax

Yup, SECOND through FIFTH are much cleaner; thanks! Quick response, too!

I'm wondering about the long-term portability of SECOND and THIRD, though, as they seem to rely on the particular way that constant is implemented.

Replies are listed 'Best First'.
Re: Re: Re: Ugly syntax
by perrin (Chancellor) on Dec 04, 2001 at 20:00 UTC
    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.

      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.