I wonder if anyone can help with a problem I'm having with the constant pragma. It has almost driven me to distraction this afternoon...
The following code snippet illustrates the problem. I define two constants near the top and then use them in two different hash definitions. The first one comes out via Data::Dumper as I would expect but in the second one the constants are not converted to the values I want and remain as the constant labels.
use strict; use warnings; use Data::Dumper; use constant E_MESYSTEM => 1; use constant E_MEENTITY => 2; my %element_type = ( system => E_MESYSTEM, entity => E_MEENTITY, ); my %generator_lookup = ( E_MESYSTEM => 'G_SYSTEM_SYSTEM_ID', E_MEENTITY => 'G_ENTITY_ENTITY_ID', ); print Dumper(\%element_type); print Dumper(\%generator_lookup); __END__ #Ouput correct $VAR1 = { 'system' => 1, 'entity' => 2 }; #Output incorrect $VAR1 = { 'E_MESYSTEM' => 'G_SYSTEM_SYSTEM_ID', 'E_MEENTITY' => 'G_ENTITY_ENTITY_ID' };
Regards,
Dom.
In reply to Problem with constant pragma and some hash definitions by dbush
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |