in reply to Re: Config::Tiny Module
in thread Config::Tiny Module

Really!? It writes just not what it should.
$Config->{section}->{ipaddress} = $newvalue; $Config->write( 'file.conf' );
The above just doesn't write. Put the $newvalue is single quotes and it write "$newvalue" !

Replies are listed 'Best First'.
Re^3: Config::Tiny Module
by Eliya (Vicar) on Mar 29, 2011 at 21:04 UTC
    Really!?

    Yes.  I tried with

    my $newvalue = '127.0.0.1'; ...

    and 127.0.0.1 is exactly what ended up in the file.

    As for single quotes: they don't interpolate, that's why you get "$newvalue" literally.

      There are 2 pages involved. The first is a form that passes the value $newvalue to the CGI script. The CGI script receives that value fine and I can dump it to screen fine.

      If I try and write that value to the config file one of two things happens. Firstly, if I single quote the value '$newvalue' it will write the literal string $newvalue to the config file. So this rules out any permissions issues with writing to the file.

      Any other format ("$newvalue" or \$newvalue) will not write to the file at all. It simply ignores it.

      If I set the variable value myself in the CGI script (that is, not pass it from a form) and then try and write that value to the file it works.
      Sorry - I should have been much clearer.

      Setting the variable in the same file works fine. Posting it from another form doesn't.

        Not sure I understand — what same file, what other form?

        You have a CGI script that receives a parameter named "newvalue" via HTTP from a form.  You said "If I print the value its fine", which means the CGI script is apparently receiving the parameter as intended.  Also, you seem to be able to update the config file in principle (as you implied above) — but maybe not from the CGI script...(?).

        In other words, what remains as a possible problem is my original suspicion that the CGI/webserver user might not be allowed to write...  So, have you checked the permissions?

        Or, put differently, is your problem that the file isn't being updated at all, or that the file is updated but the modified value is not what you think it should be?