Hey Jos,

Not sure I understand entirely, but I think I usually do #2 also.

For example, I tend to do something like this in my code.  Comments
would be appreciated.  (I have not tried to run this particular bit,
for example, I was reading and think lc %Hash will tr all the hash
value chars to lower case, but I have not tested... <g>).

Is this what you are talking about?

my @FN = split (/\./, $0);
if (!-e "$FN[0].cfg") { # Create a cfg file (if it's not there...)
    print qq[\n\tThe config file does not exist, creating $FN[0].cfg.
    \tPlease check that the settings are what you need.\n\n];
    CreateCFG();
} else { # read the cfg file
    open(CONFIG, "<$FN[0].cfg") || die "Can't open $FN[0].cfg : $!";
    while (<CONFIG>) { # process the Config file
        chomp; s/#.*//; s/^\s+//; s/\s+$//; # clean the lines
        next unless length; # anything left?
        my ($Key, $Val) = split(/\s*=\s*/, $_, 2);
        $Cfg{$Key} = "$Val\n"; # populate the hash
        chomp $Cfg{$Key};
    } # end while CONFIG
    lc %Cfg; # no caps
} # end if/else create/use .cfg

sub CreateCFG {
    open(CfgOUT, ">$FN[0].cfg") || die "Can't create $FN[0].cfg : $!";
    print CfgOUT <<endCONFIG; # Create config file
# Case and white space do not matter, use "#" for comments
Parm1 = Str  # Comment
Paramater2 = String
Parm3 = Another String # Doc on this parm
Parm4 = String
endCONFIG
}

Not sure how #1 would work, and I don't know if I want to get into
attempting to make a module #3 yet (this code I am working on may get put
in a module though.  It is fairly broad, and I couldn't find anything
that did it on cpan.)

Wednesday, June 27, 2001, 12:58:37 PM, you wrote:

JIB> I usually use a config file for this now you could do this 3 ways
JIB> as i see it

JIB> -    just have a file that holds a lot of global vars and 'require/use' that
JIB> in your mian script
JIB> -    get one hashref that you globalise and thus reduce namespace pollution
JIB> -    make it a module, give it a constructor returning a hashref and thus
JIB> not polluting *anything*

JIB> i usually use #2 for what it's worth

>>
>>   I need to pass a number of parms to my program.  Is there a "best
>>   Practice" for how to do this?  Command line is not something I want
>>   to do.
>>
>>   I did search on "Config" from search.cpan.org, but it returned 99
>>   modules!
>>
>>   Any suggestions?  In the past, I have done it by hand, but...

-- 
[EMAIL PROTECTED]
Using The Bat! eMail v1.53d
Windows NT 5.0.2195 (Service Pack 1)
How do you make Windows faster ? Throw it harder

Reply via email to