in reply to Re: Problem Modifying Files
in thread Problem Modifying Files

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

Replies are listed 'Best First'.
Re^3: Problem Modifying Files
by mikeatrcn (Acolyte) on Sep 23, 2004 at 14:11 UTC

    Thank you all for your help!

    It turned out to be a "permissions" issue. I added code to "manually" unlink the old file and rename the new, and $! gave the response "Permission denied".

    It's funny, though, that the module set permissions that allowed me to create the ini, but not to delete/rename it!

    For some reason, I didn't get the errors from the module in my error handling code below. I'm not sure if it's the module or my code, but I <think> my code's o.k.

    Again, my thanks!

    sub errMsg1() { printf "@_\n"; &msgLog ("@_\n"); &stdErr ("@_\n"); printf @Config::IniFiles::errors; for my $line (@Config::IniFiles::errors) { &stdErr ("\t$line\n"); printf "$line\n"}; };