B
bkimelman
I am using perl version 5.8.6 on a Windows XP PC.
I am having a problem using defined constants as hash keys.
Here is an examaple to demonstrate the problem
====================================
use strict;
use constant;
use Class::Struct;
use Data:
umper;
use constant OPT_BOOLEAN => 'b';
use constant OPT_STRING => 's';
use constant OPT_INTEGER => 'i';
use constant OPT_NOPARM => '-';
my ( %types );
%types = ( OPT_BOOLEAN => "boolean flag" , OPT_STRING => "string" ,
OPT_INTEGER => "integer" , OPT_NOPARM => "" ) ;
print Dumper(\%types),"\n";
exit 0;
==============================
When I run the above perl script the output from the print statement
shows the "names" of the defined constants as the values of the hash
keys. Can you get it to use the value of the defined constants as the
values of the hash keys ?
Currently I am forced into doing this until I c an solve this problem :
@parm_types = ( OPT_BOOLEAN , OPT_STRING , OPT_INTEGER , OPT_NOPARM );
@parm_type_notes = ( "boolean flag" , "string" , "integer" , "" );
%types = map { $parm_types[$_] , $parm_type_notes[$_] } ( 0 ..
$#parm_types);
I am having a problem using defined constants as hash keys.
Here is an examaple to demonstrate the problem
====================================
use strict;
use constant;
use Class::Struct;
use Data:
use constant OPT_BOOLEAN => 'b';
use constant OPT_STRING => 's';
use constant OPT_INTEGER => 'i';
use constant OPT_NOPARM => '-';
my ( %types );
%types = ( OPT_BOOLEAN => "boolean flag" , OPT_STRING => "string" ,
OPT_INTEGER => "integer" , OPT_NOPARM => "" ) ;
print Dumper(\%types),"\n";
exit 0;
==============================
When I run the above perl script the output from the print statement
shows the "names" of the defined constants as the values of the hash
keys. Can you get it to use the value of the defined constants as the
values of the hash keys ?
Currently I am forced into doing this until I c an solve this problem :
@parm_types = ( OPT_BOOLEAN , OPT_STRING , OPT_INTEGER , OPT_NOPARM );
@parm_type_notes = ( "boolean flag" , "string" , "integer" , "" );
%types = map { $parm_types[$_] , $parm_type_notes[$_] } ( 0 ..
$#parm_types);