Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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?

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" !
        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?
[Corion]: Meh. My bank removed (part of) their CSV download facilities. Now I will either have to implement a full scraper or automate the download using the HBCI interface instead (or just get a new account elsewhere...)
[Corion]: On the upside, I spend a lot of time thinking this weekend about how to actually implement rate limiting for futures, and if things work out, maybe even loading a configuration from an external file makes sense
[Corion]: I've also found some interesting invariants that I have to think/write about more. A simple rate limiter will never change the order of the input, while a limiter that allows for parallel execution will change the order. But my API currently allows for bo
[Corion]: ... for both, and I'm not sure if I want to add the cruft from the parallel API (a token that you need to hold on to while you hold the lock) to the rate limiting API too, to allow seamless up/downgrades, or not.
[Corion]: Also, rate limiting will look great with await: my $token = await $limiter-> limit($hostname); instead of my $f = $limiter->limit( $hostname )->then(sub { my( $token)=@_; ... });

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-10-23 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (277 votes). Check out past polls.

    Notices?