On Thu, Mar 5, 2009 at 12:23, "Stanisław T. Findeisen"
<sf181...@students.mimuw.edu.pl> wrote:
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> use constant {
>    SOME_CONSTANT => 'some value'
> };
>
snip
> print("The value is: " . $hash{SOME_CONSTANT} . '/' . $hash{$index} . "\n");
snip

SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT".
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
$hash{&SOME_CONSTANT} #function call method 1
$hash{SOME_CONSTANT()} #function call method 2

However, I would suggest using the ReadOnly* module for constants instead.

* http://search.cpan.org/dist/Readonly/Readonly.pm

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
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