Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Config::Tiny Module

by packetstormer (Monk)
on Mar 29, 2011 at 20:15 UTC ( #896267=perlquestion: print w/replies, xml ) Need Help??
packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to pass a variable to a new value using Config::Tiny?

I have a form that passes a value to a perl script. The value is called $newvalue. If I print the value its fine. However none of the following work to update the config file with that value:

use strict; use warnings; use diagnostics; use Config::Tiny; use CGI qw(param header); my $Config = Config::Tiny->new; $Config = Config::Tiny->read( 'file.conf' ); my $newvalue = param('newvalue'); chomp $newvalue; $Config->{section}->{ipaddress} = "\$newvalue"; #OR #$Config->{section}->{ipaddress} = \$newvalue; #OR #$Config->{section}->{ipaddress} = $newvalue; #OR #$Config->{section}->{ipaddress} = "$newvalue"; $Config->write( 'file.conf' ); print "Content-type: text/html\n\n"; print $newvalue; print <<ENDHTML

Has anyone any ideas?

Replies are listed 'Best First'.
Re: Config::Tiny Module
by Eliya (Vicar) on Mar 29, 2011 at 20:30 UTC

    Maybe you (=the webserver user who runs the CGI script) don't have permission to write to the file?

    $Config->{section}->{ipaddress} = $newvalue; $Config->write( 'file.conf' );

    works fine for me, as long as the file is writable.

      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" !

        Yes.  I tried with

        my $newvalue = ''; ...

        and is exactly what ended up in the file.

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

Re: Config::Tiny Module
by perl514 (Pilgrim) on Jan 17, 2013 at 18:26 UTC

    Hi All,


    I am working on some stuff where I needed to have most of my variables and usernames/password in a seperate file. This thread helped me understand the module a lot better. Thank you.

    Perlpetually Indebted To PerlMonks

    Win 7 at Work. Living through it....Linux at home. Loving it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://896267]
Approved by Eliya
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-04-25 23:16 GMT
Find Nodes?
    Voting Booth?