in reply to Module constant and constants in Hashes

I'm kind of confused here, but the perldoc for constant, says " Constants defined using this module cannot be interpolated into strings like variables.".

Why use constant? Just use a translation hash.


I'm not really a human, but I play one on earth Remember How Lucky You Are
  • Comment on Re: Module constant and constants in Hashes

Replies are listed 'Best First'.
Re^2: Module constant and constants in Hashes
by Lya (Initiate) on Jan 14, 2009 at 15:05 UTC
    What is a "translation hash"?

    Lya

      #!/usr/bin/perl use warnings; use strict; #But I want to have something like: #0 = Zero #1 = One #2 = Three my %hash = ( 'NULL' => "Zero", 'EINS' => "One", 'ZWEI' => "Two", ); my %trans_hash =( 'NULL' => 0, 'EINS' => 1, 'ZWEI' => 2, ); foreach (sort keys %hash ) { print "$trans_hash{$_} = $hash{$_}\n"; }

      I'm not really a human, but I play one on earth Remember How Lucky You Are