in reply to Constants and arrow notation.

You can place the constant within parens, causing it to be checked at compiletime.

use strict; use warnings; use Data::Dumper; use constant THIS => 100; print "Testing: \n"; my %hash = ( (THIS) => 200 ); print Dumper \%hash;

Try that code with the "use constant" line commented out, and you'll see it generates a compiletime error. The error you'll get is something along the lines of:

Bareword "THIS" not allowed while "strict subs" in use at mytest.pl line 12. Execution of mytest.pl aborted due to compilation errors.


Dave

Replies are listed 'Best First'.
Re^2: Constants and arrow notation.
by dmitri (Priest) on Oct 28, 2004 at 18:51 UTC
    Thank you so very much! That's exactly what I needed. Of course, this only works with use strict;.

    /dmitri dances the happy dance.