<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Perl programming assistance in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148573#M717909</link>
    <description>If I am processing a config file for options, I would do something like the following-&lt;BR /&gt; &lt;BR /&gt;($var,$val)=/^\s*(\S+)\s*=\s*(\S+)/;&lt;BR /&gt;$myopt{$var}=$val unless $myopt{$var};&lt;BR /&gt; &lt;BR /&gt;I use %myopt with a key of the variable name to hold the values and to do testing.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
    <pubDate>Thu, 18 Dec 2003 13:12:02 GMT</pubDate>
    <dc:creator>Rodney Hills</dc:creator>
    <dc:date>2003-12-18T13:12:02Z</dc:date>
    <item>
      <title>Perl programming assistance</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148570#M717906</link>
      <description>I am writing a perl script in which I have some global variables that contain vital information for the script to function.  These variables will be set to a default value upon initialization, OR by a command-line switch, OR by variable/value pairs in a configuration file.  Command-line switches must override all other methods. The configuration file is formatted according to standard perl syntax  i.e.:&lt;BR /&gt;&lt;BR /&gt;$Backup{'BCVset'} = 1;&lt;BR /&gt;$Brbackup{'BackupType'} = "online_split";&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Following is a code snippet to help explain:&lt;BR /&gt;&lt;BR /&gt;    # Open the configuration file&lt;BR /&gt;    open (CFG_FILE, "$Cfgfile");&lt;BR /&gt;    # Read the config file line by line.&lt;BR /&gt;    while (&lt;CFG_FILE&gt;){&lt;BR /&gt;      chomp;&lt;BR /&gt;      # If the line length is greater than zero&lt;BR /&gt;      # and it is not a comment do this section&lt;BR /&gt;      if (length &amp;amp;&amp;amp; !/^\s*#.*$/){&lt;BR /&gt;        # make sure the value is quoted&lt;BR /&gt;        s/\s*=\s*(\S+);/ = qw($1);/;&lt;BR /&gt;        # Capture the variable name&lt;BR /&gt;        /^(\S+)\s*=/;&lt;BR /&gt;    ##### Here I want to check if the variable&lt;BR /&gt;    #####  encounterd is already defined with &lt;BR /&gt;    #####  a value&lt;BR /&gt;        if (!defined($1)) {&lt;BR /&gt;         ...doesn't work.  $1 is always defined&lt;BR /&gt;         because of the previous match &lt;BR /&gt;         operation&lt;BR /&gt;        if (!defined($$1)) {&lt;BR /&gt;         ...doesn't work.&lt;BR /&gt;&lt;BR /&gt;any ideas would be appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;Kurt Renner&lt;/CFG_FILE&gt;</description>
      <pubDate>Thu, 18 Dec 2003 12:32:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148570#M717906</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2003-12-18T12:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Perl programming assistance</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148571#M717907</link>
      <description>Sorry for the formatting of the code.  I put it in a .txt attachment so it's easier to follow.</description>
      <pubDate>Thu, 18 Dec 2003 12:35:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148571#M717907</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2003-12-18T12:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Perl programming assistance</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148572#M717908</link>
      <description>Let's try that again....</description>
      <pubDate>Thu, 18 Dec 2003 12:37:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148572#M717908</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2003-12-18T12:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Perl programming assistance</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148573#M717909</link>
      <description>If I am processing a config file for options, I would do something like the following-&lt;BR /&gt; &lt;BR /&gt;($var,$val)=/^\s*(\S+)\s*=\s*(\S+)/;&lt;BR /&gt;$myopt{$var}=$val unless $myopt{$var};&lt;BR /&gt; &lt;BR /&gt;I use %myopt with a key of the variable name to hold the values and to do testing.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 18 Dec 2003 13:12:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148573#M717909</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-12-18T13:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Perl programming assistance</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148574#M717910</link>
      <description>Rodney,&lt;BR /&gt;  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.&lt;BR /&gt;&lt;BR /&gt;  This solves my problem.  Your suggestion would also work.  Thanks for your input.</description>
      <pubDate>Thu, 18 Dec 2003 13:34:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-programming-assistance/m-p/3148574#M717910</guid>
      <dc:creator>Kurt Renner</dc:creator>
      <dc:date>2003-12-18T13:34:27Z</dc:date>
    </item>
  </channel>
</rss>

