Hi,
I used this module once on win32 and remember that there were some problems using it.. If I created new IniFiles objects with the -file parameter and the file supplied did not exist or if the file existed but was empty, then the the new() method just didn't return any object..

For the -file parameter to work 1) the ini file had to exist and 2)there had to be atleast one section in the file!?..weird..

I guess there is some "UNIX-to-Windows"-issues" that is causing the problem in the module..

use Config::IniFiles; use strict; updtDescrip(); sub updtDescrip() { my $tmpPthFil = q(test.ini); #Create ini file with one dummy section if 1)it does not exist + or 2)exists but zero size if (not -e $tmpPthFil or ( (-e $tmpPthFil) and (-z $tmpPthFil) ) + ) { open INI, ">$tmpPthFil"; print INI "[Ini]"; close INI; } #Now the -file option is working ok. my $tmpIni = new Config::IniFiles( -file => $tmpPthFil, -allowedco +mmentchars => '*', -nocase => '1', ); #Output sections that already exist in ini file. foreach ($tmpIni->Sections) { print "Section:$_\n"; } #Add a new section and parameter with a value $tmpIni->newval('apps', 'app1', 'bull.exe', ); $tmpIni->newval('apps', 'app2', 'bull2.exe', ); #Set already existing parameter value in a section $tmpIni->setval ('apps', 'app1', 'app99.exe'); #Retrives existing parameter value in a section my $app = $tmpIni->val ('apps', 'app1'); print "\nApp1 is $app"; #Save config file $tmpIni->WriteConfig ($tmpPthFil); } config file after run: [ini] [apps] app1=app99.exe app2=bull2.exe


In reply to Re^2: Problem Modifying Files by ldln
in thread 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.