On Fri, Mar 06, 2009 at 09:31:44AM +0100, "Stanisław T. Findeisen" wrote:

> Chas. Owens wrote:
>> SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT".
>
> Why is it so? This is crazy.

Were it not so, every time you created a sub with the same name as one
of your hash keys you would find the result of your sub being used
instead of the hash key.  This is called action at a distance and is
generally thought to be a bad thing.

>> This is one of the drawbacks to the constant pragma.  Change the code
>> hash keys to one of these and it will work the way you want it to:
>>
>> $hash{+SOME_CONSTANT} #unary plus
>
> What is this unary plus?

The opposite of a unary minus.  In this case it is a trick to let the
parser know that SOME_CONSTANT is not a bareword.  It's not the solution
I would use.

>> $hash{&SOME_CONSTANT} #function call method 1
>> $hash{SOME_CONSTANT()} #function call method 2

This one is.

>> However, I would suggest using the ReadOnly* module for constants instead.
>>
>> * http://search.cpan.org/dist/Readonly/Readonly.pm
>
> Thanks. Hmm, they say it is slow  
> (http://search.cpan.org/dist/Readonly/Readonly.pm#CONS).

But is it too slow for you?  If all you wanted was speed of execution
you would have chosen another language, right?  And did you read the
second paragraph there?

> Why aren't there constants in the language itself?? This is crazy.

I suppose the answer to that depends on your definition of "constant",
"in" and "crazy".

> Also: is that true that Perl's specification is its implementation by  
> Larry Wall? This is even more crazy. :-/

You're really going to have to tell us what you mean by "crazy".  If you
just mean that you'd prefer a full specification and multiple
implementations then you might be pleased with the direction that Perl 6
is taking.  Otherwise, the current situation seems to have worked pretty
well for the last 21 years.

> A language and its implementation are (should be) 2 different things!

Or perhaps not?

> Gunnar Hjalmarsson wrote:
>> So, what behavior exactly is it that you consider weird? What output had you 
>> expected?
>
> I'd expect equal hash keys to map to equal values.
> I'm a conservatist. :-)

Then you'll be pleased to know that perl is not crazy in this respect,
at least.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to