- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl programming assistance
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 04:32 AM
тАО12-18-2003 04:32 AM
$Backup{'BCVset'} = 1;
$Brbackup{'BackupType'} = "online_split";
.
.
etc
Within the main script, I want to check to see if the variable is already defined (as the result of a command line switch) when the variable/value is encountered in the configuration file. When done reading the configuration file, any required variable that was not set as a result of a command-line switch or a setting in the configuration file will be defaulted to a set value.
Following is a code snippet to help explain:
# Open the configuration file
open (CFG_FILE, "$Cfgfile");
# Read the config file line by line.
while (
chomp;
# If the line length is greater than zero
# and it is not a comment do this section
if (length && !/^\s*#.*$/){
# make sure the value is quoted
s/\s*=\s*(\S+);/ = qw($1);/;
# Capture the variable name
/^(\S+)\s*=/;
##### Here I want to check if the variable
##### encounterd is already defined with
##### a value
if (!defined($1)) {
...doesn't work. $1 is always defined
because of the previous match
operation
if (!defined($$1)) {
...doesn't work.
any ideas would be appreciated.
Thanks!
Kurt Renner
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 04:35 AM
тАО12-18-2003 04:35 AM
Re: Perl programming assistance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 04:37 AM
тАО12-18-2003 04:37 AM
Re: Perl programming assistance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 05:12 AM
тАО12-18-2003 05:12 AM
Solution($var,$val)=/^\s*(\S+)\s*=\s*(\S+)/;
$myopt{$var}=$val unless $myopt{$var};
I use %myopt with a key of the variable name to hold the values and to do testing.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 05:34 AM
тАО12-18-2003 05:34 AM
Re: Perl programming assistance
I have found a little simpler way of doing what I want. It's less efficient, but easier for me to deal with. I have a ParseArgs routine that's called first. I need this to get one critical piece of information from the command-line arguments. I then read the configuration file and override any variables specified in the config file by doing a "eval $_" per line. I then call the ParseArgs routine again to override any variables set via the config file with the passed arguments.
This solves my problem. Your suggestion would also work. Thanks for your input.