in reply to Re^2: why doesn't constant work?
in thread why doesn't constant work?
#/usr/bin/perl use strict; use warnings; use constant { Undefined => 0, Page => 1, Index => 2, }; {my %map = ( Page => 'mypage', Index => 'myindex', ); use Data::Dumper qw(Dumper); print Dumper \%map;} {my %map = ( Page() => 'mypage', Index() => 'myindex', ); print Dumper \%map;}
And this is why Perl Best Practices says to use Readonly (with Readonly::XS installed, preferably) instead of constant.
Well, one of the reasons anyway. Another is string interpolation. And I think there are more, though I can't remember them off the top of my head :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: why doesn't constant work?
by ELISHEVA (Prior) on Nov 11, 2010 at 13:39 UTC | |
by JavaFan (Canon) on Nov 11, 2010 at 14:08 UTC |