Re: hashes + use constant - weird behavior

2010-05-14 Thread Dr.Ruud
Stanisław T. Findeisen wrote: use constant { SOME_CONSTANT => 'some value' }; $hash{SOME_CONSTANT} = 'value 1'; Not weird at all, just works as documented. So change to either: $hash{ +SOME_CONSTANT } = 'value 1'; or: $hash{ SOME_CONSTANT() } = 'value 1'; -- Ruud -- To uns

Re: hashes + use constant - weird behavior

2009-03-06 Thread Chas. Owens
On Fri, Mar 6, 2009 at 03:31, "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. Because it is nicer to say $hash{key} than $hash{"key"} and Perl is optimized for the common case. When you

Re: hashes + use constant - weird behavior

2009-03-06 Thread Jenda Krynicky
From: "Stanisław T. Findeisen" > Chas. Owens wrote: > > SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT". > > Why is it so? This is crazy. Because most often you want it that way. Most often you do want the $hash{BLAHBLAH} to mean $hash{'BLAHBLAH'} and not have to put qu

Re: hashes + use constant - weird behavior

2009-03-06 Thread Paul Johnson
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 f

Re: hashes + use constant - weird behavior

2009-03-06 Thread Stanisław T. Findeisen
Chas. Owens wrote: SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT". Why is it so? This is crazy. 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

Re: hashes + use constant - weird behavior

2009-03-05 Thread Gunnar Hjalmarsson
Stanisław T. Findeisen wrote: #!/usr/bin/perl use warnings; use strict; use constant { SOME_CONSTANT => 'some value' }; my $index = 'some value'; my %hash = (); $hash{SOME_CONSTANT} = 'value 1'; $hash{$index} = 'value 2'; print("The value is: " . $hash{SOME_CONSTANT} . '/' . $hash{$index

Re: hashes + use constant - weird behavior

2009-03-05 Thread Chas. Owens
On Thu, Mar 5, 2009 at 12:23, "Stanisław T. Findeisen" 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

hashes + use constant - weird behavior

2009-03-05 Thread Stanisław T. Findeisen
#!/usr/bin/perl use warnings; use strict; use constant { SOME_CONSTANT => 'some value' }; my $index = 'some value'; my %hash = (); $hash{SOME_CONSTANT} = 'value 1'; $hash{$index} = 'value 2'; print("The value is: " . $hash{SOME_CONSTANT} . '/' . $hash{$index} . "\n"); print("Comparison 1: