mikeatrcn has asked for the wisdom of the Perl Monks concerning the following question:
I'm using the Config::IniFiles module to update some existing ini files, and cannot get it to replace the existing ini with the updated one. It leaves the temporary file (ending in "-new") and doesn't rename it to the original name. As a test, I tried to rename it myself, using unlink/rename, as commented-out in the code, but that didn't work either, nor did I get the "die" messages.
I'm still new at Perl, so I'm sure it's something pretty basic but, after looking through the various sites all morning, I'm lost. Your help is hugely appreciated!
The relevant code snippet follows:
sub updtDescrip() { my $tmpPthFil = "$demoQcPth"."tmp_drs_demoqc$mm$yy$c\.ini"; # Get a temp. ini object $tmpIni = new Config::IniFiles( -file => $tmpPthFil, -allowedcomme +ntchars => '*', -nocase => '1'); if (!defined($tmpIni)) { &errMsg2 ("Failure re-accessing \"tmp_\" DRS file. Program +will abend."); &errMsg1 (" File: $tmpPthFil"); &abend (); }; my $tmpVal = $tmpIni->val( "Application", "Description"); # + Section, Key if (!defined($tmpIni)) { &errMsg2 ("The \"Description\" value cannot be found. Progr +am will abend."); &errMsg1 (" File: $tmpPthFil"); &abend(); }; # insert, e.g., "1104 / " before the descri +ption $tmpVal =~ s/(\w+)/DemoQC $mm$yy \/ $1/; # $tmpVal = $tmpIni->setval( "Application", "Description", $tmpVal); # +Section, Key if (!defined($tmpIni)) { &errMsg2 ("Resetting the \"Description\" value failed. Prog +ram error. Program will abend."); &errMsg1 (" File: $tmpPthFil"); &abend(); }; # Rewrite the ini file $tmpIni->RewriteConfig($tmpPthFil); if (!defined($tmpIni)) { &errMsg2 ("Failure re-accessing \"tmp_\" DRS file. Program +will abend."); &errMsg1 (" File: $tmpPthFil"); &abend (); }; printf(" DemoQc descrip: $tmpVal \n tmpPthFile: $tmpPthFil\n"); # unlink("$tmpPthFil") or die ("Failure deleting: $!"); # rename("$tmpPthFil\-new", "$tmpPthFil") or die ("Failure renaming +: $!"); };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem Modifying Files
by Random_Walk (Prior) on Sep 22, 2004 at 16:34 UTC | |
by mikeatrcn (Acolyte) on Sep 22, 2004 at 18:07 UTC | |
by fglock (Vicar) on Sep 22, 2004 at 19:26 UTC | |
by mikeatrcn (Acolyte) on Sep 22, 2004 at 19:40 UTC | |
by Random_Walk (Prior) on Sep 23, 2004 at 08:25 UTC | |
by ldln (Pilgrim) on Sep 23, 2004 at 00:04 UTC | |
by mikeatrcn (Acolyte) on Sep 23, 2004 at 14:11 UTC |