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 +: $!"); };
In reply to Problem Modifying Files by mikeatrcn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |