"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

-- 
Affijn, Ruud

"Gewoon is een tijger."

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to