Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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?

Comment on Config::Tiny Module
Download Code
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" !
        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.

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://896267]
Approved by Eliya
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-12-26 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (174 votes), past polls