hesco has asked for the wisdom of the Perl Monks concerning the following question:

Jarich:

Thank you sir, for those leads.

I've been running tests with Config::IniHash. Its working on every part of my barely edited config files, except for the heredoc variables in my supporters.copy.ini file.

But now I'm getting this error:

Wed Nov 30 16:41:47 2005 error client 24.67.197.93 Can't use an undefinedvalue as a HASH reference at /usr/lib/cgi-bin/bc/test.pl line 24.

line 24 reads:

my $options->{'heredoc'} = '1';
I know someone here the other day was telling me I should not quote my hash keys, but on my installation it does not seem to work unless I do.

#!/usr/bin/perl use strict; # use supporters_conf qw(%config); use Config::IniHash; # $hashreference = ReadINI ($filename, %options); use CGI; use CGI::Pretty qw(:all *table param); my $url = url(); # my $table1 = fqtn(@config{qw(db prefix)},"basetablename"); my $conf += parse_config_directory($url); my $path = $0; my $script = $0; $script =~ s/^(.*)\///; # $conf =~ s/$script//; # $path =~ s/$script/conf.d\/$conf\/supporters.conf/; my $config_conf = ReadINI ($conf); my $copy = $conf; $copy =~ s/\.conf/.copy/; my %options; my $options->{'heredoc'} = '1'; my $config_copy = ReadINI ($copy,%options); my $db = $conf; $db =~ s/\.conf/.db/; my $config_db = ReadINI ($db); print header("Testing parser for configuration files"), start_html("Testing parser for configuration files"), p("And the question of the hour is: Will the config module export t +h +e form copy. This experiment shall tell us."), p("Script path and name is: ".$0), p("Script name is: ".$script), # p("Scriptpath: ".$sp), # p("Scriptname: ".$sn), p("Path to configuration files at: <b>".$conf."</b>"), p("Script accessible at: ".$url), # p("Fully Qualified Table Name looks like: ".$table1), p("Config::IniHash says \$config = ".$config_conf."."), p("And the mail-abuse address is: ".$config_conf->{'mail-server'}->{ + +'mail_abuse'}."."), p("The database name is: ".$config_db->{'db'}->{'db_name'}."."), p("The donor form disclaimer reads: <br>".$config_copy->{'copy'}->{'do +nor_form_disclaimer_copy'}."."), p(),p(), $supporters_conf::config{'donor_thanks'}, end_html(); exit; sub parse_config_directory() { my($conf)=@_; # call as follows # use CGI; # $url = url(); # $conf = parse_config_directory($url); my $scriptpath = $0; my $scriptname = $0; $scriptname =~ s/^(.*)\///; $scriptpath =~ s/$scriptname//; $conf =~ s/https:\/\///; $conf =~ s/http:\/\///; $conf =~ s/\//./g; $conf =~ s/\.$scriptname//; $conf = $scriptpath."conf.d/".$conf."/supporters.conf.ini"; return $conf; # configuration file, ready for execution } # END parse_config_directory() sub fqtn(){ my($db,$prefix,$table)=@_; $db =~ s/ *$//; $prefix =~ s/ *$//; $table =~ s/ *$//; my $fullyqualifiedtablename = $db.".".$prefix.$table; return $fullyqualifiedtablename; } # END fqtn
Any ideas how I might work through this one? I've written this multiple ways and keep getting one error or another.

-- Hugh

Replies are listed 'Best First'.
Re: Config::IniHash heredoc errors.
by GrandFather (Saint) on Dec 01, 2005 at 07:42 UTC

    $options-> is a reference. It referes to something (it doesn't matter what for the moment). When you write my $options you have not given $options a value, it is undef. -> doesn't work with an undefined value. You could do this:

    my $options = {}; $options->{'heredoc'} = '1';

    Which sets $options to refer to an empty hash, then assignes a key/value pair to the hash

    However, looking at the code in context what you really want is:

    my %options; $options{'heredoc'} = '1'; my $config_copy = ReadINI ($copy,%options);

    The dereference operator is completely bogus in this context.


    DWIM is Perl's answer to Gödel
      Thank you sir.

      That clarification; and dropping the oo -> notation got me past the compile time errors, to a webpage which failed to produce the anticipated result.

      Now I think I need to dig further into the Config::IniHash docs to figure out why my heredoc configuration variables are not being populated and / or passed.

      -- hugh

      OK. I've made multiple attempts at this one, setting $config{heredoc} = 1; = 'ON'; = 'on'; etc. But I can not seem to get this feature of this module to work for me.

      An important element of my application's configuration scheme is to pull client specific copy out of domain-specific configuration files and to use it to decorate otherwise stock web forms.

      Does anyone here have any experience successfully using this feature. Can you please share with me a snippet of working code from your script which uses Config::IniHash as well as the .ini file itself?

      I would certainly appreciate having a working model to work from. And would love to shift maintainance of the configuration module from our project to a module with broader applicability.

      -- Hugh

Re: Config::IniHash heredoc errors.
by GrandFather (Saint) on Dec 03, 2005 at 01:52 UTC

    I think what you want is:

    my $config_conf = ReadINI ($conf, heredoc => 1);

    which allows HEREDOC type lines in the .ini file.


    DWIM is Perl's answer to Gödel