in reply to hash and constants

That is not a constant hash, that is a constant reference to a hash:

use strict; use warnings; use constant GROUPS => { A => 1, B => 2, C => 3 }; GROUPS->{B} = 22; GROUPS->{D} = 'Not a constant!'; use Data::Dumper; warn Dumper [GROUPS]; __END__ $VAR1 = [ { 'A' => 1, 'D' => 'Not a constant!', 'C' => 3, 'B' => 22 } ];

Update: have a look at Readonly

Replies are listed 'Best First'.
Re^2: hash and constants
by Anonymous Monk on Nov 19, 2009 at 23:30 UTC
    Actually i have to correct the code I posted before. while ( my ($k,$val) = each %{ +GROUPS } ) { So my actual question is, how I can use $k in each(), so that it repre +sents A and B. while ( my ($name,$value) = each ( what I have use here?)) { print $name{value} ; } }