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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.