hello everyone,
i have to write a program which will take a command line arguement which is nothing but a constant name. in the program i am trying to print out the value corresponding to the constant name provided.
i am aware of converting a string to a variable name as follows.
[code=perl]
my $name = "mohan";
my $var = "name";
my $new = $$name;
print "your name is : " . $name . "\n";
[/code]
But here i have to get the constant value corresponding to the command line arguement passed.
I have tried in the following way.
i have kept the constants in a pm file.
Test_Cfg.pm file is as follows.
[code=perl]
#file name : Test_Cfg.pm
#!/usr/bin/perl
package Test_Cfg;
use constant NAME => "mohan";
use constant USERID => "mpgutta";
use constant EMPID => 12345;
1;
[/code]
perl script is as follows.
[code=perl]
#!/usr/bin/perl
my $mode = $ARGV[0];
print $mode; # This is just printing the arguement. not the costant value.
print ${"$mode"}; # this is not printing anything at all.
[/code]
could anybody assist me in getting the constant value from a string.
i have to write a program which will take a command line arguement which is nothing but a constant name. in the program i am trying to print out the value corresponding to the constant name provided.
i am aware of converting a string to a variable name as follows.
[code=perl]
my $name = "mohan";
my $var = "name";
my $new = $$name;
print "your name is : " . $name . "\n";
[/code]
But here i have to get the constant value corresponding to the command line arguement passed.
I have tried in the following way.
i have kept the constants in a pm file.
Test_Cfg.pm file is as follows.
[code=perl]
#file name : Test_Cfg.pm
#!/usr/bin/perl
package Test_Cfg;
use constant NAME => "mohan";
use constant USERID => "mpgutta";
use constant EMPID => 12345;
1;
[/code]
perl script is as follows.
[code=perl]
#!/usr/bin/perl
my $mode = $ARGV[0];
print $mode; # This is just printing the arguement. not the costant value.
print ${"$mode"}; # this is not printing anything at all.
[/code]
could anybody assist me in getting the constant value from a string.
Comment