Issue with use of Configuration file instead of hardcoded values inside the script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Issue with use of Configuration file instead of hardcoded values inside the script
# 1  
Old 07-29-2011
Issue with use of Configuration file instead of hardcoded values inside the script

Hi,

My code works perfectly fine.
But,
Code:
$my $min_to_add = 1 * 1 * 60;

and
Code:
my $hr_to_sub = 1 * 1 * 86400;

i may need to change the values in future. so am keeping them in a separate configuration file like

Code:
MIN = 1 * 1 * 60 
HR = 24 * 60 * 60

in the script, i use a package use et_config and Et_Config_Init()
I call them inside the script like
Code:
my $min_to_add = Et_Config_Value("MIN");
my $hr_to_sub = Et_Config_Value("HR");

The issue here is, when i use those values directly in the script, it takes the multiplied value as 1 * 1 * 60 =60 but when i get them from the configuration file, it remains as 1 * 1 * 60 only as such , so i am not getting the result expected.

Is there any function that can do this?
The configuration file is mandatory. How can this be achieved?

Code:

Code:
my $date_var = "Jun 6 2011 8:02AM";
if ($date_var != '')
{
my $min_to_add = 1 * 1 * 60;
my $from_dt = qx/
date -d "$date_var" +%s
/ + $min_to_add;
my $min_var = strftime( '%B %d %Y %I:%M%p', localtime $from_dt );
print("\n the mins added is $min_var\n");

my $hr_to_add = 1 * 60 * 60;
my $to_dt = qx/
date -d "$min_var" +%s
/ + $hr_to_add;
my $hr_var = strftime( '%B %d %Y %I:%M%p', localtime $to_dt );
print("\n the hours added is $hr_var\n");
}
else
{
use POSIX qw(strftime);
my $to_dt = strftime "%b %d %Y %H:%M%p", localtime;
print("\n The original time is $to_dt\n");
my $hr_to_sub = 1 * 1 * 86400;
my $from_dt
= qx/
date -d "$to_dt" +%s
/ - $hr_to_sub;
my $to_dt_now = strftime( '%B %d %Y %H:%M%p', localtime $from_dt );
print("\n the to date now is $to_dt_now \n");
}


Last edited by pludi; 07-29-2011 at 08:48 AM..
# 2  
Old 07-29-2011
This should work:
Code:
my $min_to_add = eval Et_Config_Value("MIN");
my $hr_to_sub = eval Et_Config_Value("HR");

But they say using "eval" is dangerous.
# 3  
Old 07-29-2011
Thanks This works fine.
But is there any other option that can be used instead of Eval?
After getting it into a variable, is it possible to do the multiplication?
# 4  
Old 07-29-2011
Quote:
After getting it into a variable, is it possible to do the multiplication?
Nope (without eval). To do "right" you should validate your variables and then "eval" them. Something like this:
Code:
$min = eval $min if $min =~ /^[0-9*]+$/;

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replacing values inside a file.

Good day guys, I'm having trouble in creating a logic when it comes to replacing the values inside a file. I tried using sed command but it just doesn't work the way I want it to be. Here is what I'm trying to achieve. If my input file contains the values below. NAME++GUEST1 ++GUESS2++... (3 Replies)
Discussion started by: asdfghjkl
3 Replies

2. Shell Programming and Scripting

Issue with ls command inside script

Hi , DIR1 has only one file with .txt extension , trying to get the size of that file using the following script #!/bin/ksh foldr_1="/etc/DIR1" #echo "$foldr_1" sze_fdr1=$(ls -ltr foldr_1/*.txt |awk '{ print $5 }') echo "$sze_fdr1" After executing the above script getting... (1 Reply)
Discussion started by: smile689
1 Replies

3. Shell Programming and Scripting

Taking sum up all values inside the file

Hi, Taking sum up all values inside the file by using the below command: paste -sd+ filenmae | bc Getting some error like "0705-001: building space exceeded on line1 stdin" The original data looks like SPACE SPACE SPACE 0.123 JOBNAME1 SPACE SPACE 20.325 JOBNAME2 SPACE SPACE... (2 Replies)
Discussion started by: NareshN
2 Replies

4. Shell Programming and Scripting

error in shell script while returning values-- urgent issue plz help.

Hi, I have initailized a varaible EBID as typeset Long EBID=0 i am calculating value of EBID using certian formula as below: (( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE )) return $CURR_EBID The output is as below: + (( CURR_EBID=... (6 Replies)
Discussion started by: kasanur
6 Replies

5. Shell Programming and Scripting

Script to increase Timeout values in Configuration File

Hi Guys I am using one configuration file for reading some time out values.The format of the file is A.Type = Number A.Val = 2000 B.Type = Number B.Val = 4000 Now my requirement is I need to write a shell script in Solaris where i need to increase these timeout values by 10 times of... (3 Replies)
Discussion started by: mr_deb
3 Replies

6. Shell Programming and Scripting

extracting values from configuration file

Dear All, i am new to shell scripting, I am working on embedded system based on linux.I am supposed to the read the configuration file and edit another file. presently I would like to read from the configuration file.It would be having values file one below. There is chance of entering... (6 Replies)
Discussion started by: Ratheendran
6 Replies

7. Shell Programming and Scripting

connection string is hardcoded

Hi, I have many perl scripts in single server, i am new to perl, suggestions are appreciated. connection string is hardcoded in all perl scripts i need to make change the all perl scripts and there should be only one config file available in that server. destination database is mysql... (3 Replies)
Discussion started by: prakash.gr
3 Replies

8. Shell Programming and Scripting

Webalizer issue when inside script

hello gurus, When i run the command on shell webalizer -p -n mydomain.com -c /path/to/my/log/webalizer.conf it works fine and it creates stats for the given mydomain.com in the target output directory but when i put it in a script same command and parameters but it goes weird and it... (0 Replies)
Discussion started by: eyes_drinker
0 Replies

9. Shell Programming and Scripting

how to find Script file location inside script

I have to find out the file system location of the script file inside script. for example a script "abc.sh" placed anywhere in the file system when executed shold tell by itself the location of it. example #pwd / #./abc this is / #cd /root #./abc this is /root #cd / #/root/abc this... (10 Replies)
Discussion started by: asami
10 Replies

10. Shell Programming and Scripting

script to read configuration file

Hi, I would like to write a Korn shell script which will remove files older than a certain date. In my script, it will read a configuration file with the following entries: # <directory> <filename wildcard> # /home/philip/log *.log /home/philip/log1 delete-me*.log The... (1 Reply)
Discussion started by: philip_dba
1 Replies
Login or Register to Ask a Question