Code:
#!/usr/bin/perl use Config::Simple; $cfg = new Config::Simple(syntax=>'ini'); $cfg->param('auth.user', 'sherzodR'); $cfg->param('auth.pass', 'mypass'); $cfg->write("new.cfg");
File structure:
#cat new.cfg ; Config::Simple 4.58 ; Tue Jul 7 11:20:58 2015 [auth] pass=mypass user=sherzodR
Reading the values:
#!/usr/bin/perl use Config::Simple; $cfg = new Config::Simple(); $cfg->read('new.cfg'); $user = $cfg->param("auth.user"); $pass=$cfg->param("auth.pass"); printf ("Username:%s Password:%s\n", $user,$pass);
On running:
#./testconfig.pl Username:sherzodR Password:mypass
Reading and then updating the values:
use Config::Simple; $cfg = new Config::Simple(); $cfg->read('new.cfg'); $user = $cfg->param("auth.user"); $pass=$cfg->param("auth.pass"); printf ("Username:%s Password:%s\n", $user,$pass); $cfg->param('auth.user', 'newuser'); $cfg->write("new.cfg");
On running:
#./testconfig.pl Username:sherzodR Password:mypass [[email protected]] ~/scripts #./testconfig.pl Username:newuser Password:mypass
Joel G Mathew, known in tech circles by the pseudonym Droidzone, is an opensource and programming enthusiast.
He is a full stack developer, whose favorite languages are currently Python and Vue.js. He is also fluent in Javascript, Flutter/Dart, Perl, PHP, SQL, C and bash shell scripting. He loves Linux, and can often be found tinkering with linux kernel code, and source code for GNU applications. He used to be an active developer on XDA forums, and his tinkered ROMS used to be very popular in the early 2000s.
His favorite pastime is grappling with GNU compilers, discovering newer Linux secrets, writing scripts, hacking roms, and programs (nothing illegal), reading, blogging. and testing out the latest gadgets.
When away from the tech world, Dr Joel G. Mathew is a practising ENT Surgeon, busy with surgeries and clinical practise.