473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

dereferenceing a string to a constant name

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.
Expand|Select|Wrap|Line Numbers
  1. my $name = "mohan";
  2. my $var = "name";
  3. my $new = $$name;
  4. print "your name is : " . $name . "\n";
  5.  
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.
Expand|Select|Wrap|Line Numbers
  1. #file name : Test_Cfg.pm
  2. #!/usr/bin/perl
  3. package Test_Cfg;
  4. use constant NAME => "mohan";
  5. use constant USERID => "mpgutta";
  6. use constant EMPID => 12345;
  7. 1;
  8.  
perl script is as follows.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. my $mode = $ARGV[0];
  3. print $mode; # This is just printing the arguement. not the costant value.
  4. print ${"$mode"}; # this is not printing anything at all.
  5.  
could anybody assist me in getting the constant value from a string.
Sep 18 '08 #1
1 2385
KevinADC
4,059 Expert 2GB
Your question with the sample code is confusing. You say your perl program will take a command line argument, but then you show that the "name" comes from an external file, which is it?
Sep 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lawrence | last post by:
I've waited 6 weeks for an answer to my other question and still no luck, so let me rephrase the question. I know I can do this: <form method="post" action="$self"> <input type="text"...
3
by: Paul Kirby | last post by:
Hello All I am trying to create a function that returns a string like the following: // defined in headerfile // void test_func(char *retstr); // -------------------- // // c/cpp File //
18
by: William | last post by:
I have the following javascript function that updates a scroll_list and sends the updated entry (with its index) to a server script ( i.e. http://mkmxg00/cgi/confirmUpload.pl ) for further...
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
1
by: Peter | last post by:
Hi, I know that it is possible to build up a variable name based on a string and another variable name i.e. $varnum=5; ${"varnumber_$varnum"} = 'This variable should be called varnumber_5'; ...
1
by: macupryk | last post by:
+ ex {"The name \"CHARACTER\" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted."}...
6
by: DaTurk | last post by:
I'm converting MC++ to C++/CLI and for some reason it's not cool with static const System::String^ How am I supposed to have static constant strings then?
10
by: baje | last post by:
//new to c++ //have a pointer char *name; //want to enter a name *name = "dave"; //initialize cout<<"enter a name" cin>>name; cout<<" name entered is"<<name; //get a compiler error
1
by: kellysgirl | last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written. The instructions I was given are as follows In this case, you will create...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.