in reply to Config file default options?

Do you mean somthing like this?
use warnings; use strict; use Config::IniHash; # parse the config file into a hashref my $config = ReadINI 'pm1562.ini'; # default values my $defaults = { header => { to => 'foo', from => 'bar' } }; # iterate the defaults and put them into $config if they not # already exist for my $section ( keys %{$defaults} ) { for my $option ( keys %{$defaults->{$section}} ) { $config->{$section}->{$option} = $defaults->{$section}->{$opti +on} unless exists $config->{$section}->{$option}; } } #use the values, no need for a variable $to or $from print $config->{header}->{to}, "\n", $config->{header}->{from}, "\n",
Given a config file like
[header] to=holli
this prints
holli bar
Just as i think you need it.

edit: added jonadab's sugguestion.


holli, /regexed monk/

Replies are listed 'Best First'.
Re: Config file default options?
by jonadab (Parson) on Sep 07, 2006 at 11:46 UTC
    $config->{$section}->{$option} = $defaults->{$section}->{$option} unless $config->{$section}->{$option};

    I would throw the word exists (or defined) in there after the unless, just in case a user ever wants to specify a false value (e.g., a blank subject line is very rarely a good idea, but occasionally when sending mail to certain kinds of really old autoresponders that read commands from the subject line it can be desirable; there are also highly specialised cases for a blank From field).


    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.