qazwart has asked for the wisdom of the Perl Monks concerning the following question:
I know that there is now a constant pragma which is used like this:*FOO = \"bar";
But, I never really liked it because you cannot easily interpolate constants in strings using this method:use constant FOO => "bar";
Plus, I have a tendency to do this:*FOO = \"BAR"; print qq(\$FOO is set to "$FOO"\n); use constant FOO => "BAR"; print qq(Constant "FOO" is set to ) . FOO . qq(\n);
However, I know I am in the extremely tiny minority who still use the reference method of making constants, so there must be a major advantage of using the constant pragma that made everyone want to change over.use constant FOO => "BAR"; print "The value of FOO is $FOO\n";
What are the advantages of the newer constant pragma vs. the older reference method of declaring a constant?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Constants in Perl
by davorg (Chancellor) on Feb 28, 2006 at 15:47 UTC | |
by moklevat (Priest) on Feb 28, 2006 at 16:58 UTC | |
by Anonymous Monk on Feb 28, 2006 at 18:26 UTC | |
by the_slycer (Chaplain) on Mar 01, 2006 at 01:15 UTC | |
by jhourcle (Prior) on Mar 01, 2006 at 14:22 UTC | |
|
Re: Using Constants in Perl
by Fletch (Bishop) on Feb 28, 2006 at 15:25 UTC | |
|
Re: Using Constants in Perl
by diotalevi (Canon) on Mar 01, 2006 at 01:30 UTC | |
|
Re: Using Constants in Perl
by xdg (Monsignor) on Feb 28, 2006 at 21:48 UTC | |
|
Re: Using Constants in Perl
by theshz (Sexton) on Feb 28, 2006 at 19:12 UTC | |
by Fletch (Bishop) on Feb 28, 2006 at 19:19 UTC | |
by theshz (Sexton) on Feb 28, 2006 at 21:10 UTC | |
by diotalevi (Canon) on Mar 01, 2006 at 01:32 UTC | |
by Fletch (Bishop) on Mar 01, 2006 at 13:38 UTC |