Dr.Ruud wrote:
"Mr. Shawn H. Corey" schreef:
2) Perl does not have true constants. When you `use constant` you
actually create a sub that returns a value. This:
use constant VAR => "someval";
is the same as:
sub VAR {
return "someval";
}
Perl has true constants.
"use constant" isn't the same as defining a sub.
$ perl -MO=Deparse -e'
use constant ANSWER => 42;
sub DUMMY{1}
my $x = ANSWER + DUMMY;
my ($y, $z)= 0 ? (ANSWER + DUMMY, 0) : (0, ANSWER + DUMMY);
'
use constant ('ANSWER', 42);
sub DUMMY {
1;
}
my $x = 42 + DUMMY();
my($y, $z) = (0, 42 + DUMMY());
-e syntax OK
Yes it is, but you have to define it correctly:
$ perl -MO=Deparse -e'
use constant ANSWER => 42;
sub DUMMY (){1}
my $x = ANSWER + DUMMY;
my ($y, $z)= 0 ? (ANSWER + DUMMY, 0) : (0, ANSWER + DUMMY);
'
sub DUMMY () { 1 }
use constant ('ANSWER', 42);
my $x = 43;
my($y, $z) = (0, 43);
-e syntax OK
See the "Constant Functions" section of perlsub.pod:
perldoc perlsub
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/