in reply to Problem with IniFile module

Two errors, one syntactical and one conceptional. The conceptional error first :

Did you check that $ini is a valid value ? I'd rather propose :

my $inifilename = 'C:\Downloads\Perl\test.ini'); my $ini = new IniFile($inifilename); if (! defined $ini) { die "Couldn't open $inifilename : $!\n"; };

When you use the above code, Perl / your script will tell you that it couldn't find the .ini file. This is because you used single backslashes (\) to delimit the directories. This is wrong. Either use double backslashes, or, even better, use forward slashes, as both, Unix and DOS/Win32 understand these in a filename. So the best way to use it would be :

my $inifilename = 'C:/Downloads/Perl/test.ini'); -f $inifilename || die "Couldn't find $inifilename\n"; my $ini = new IniFile($inifilename); if (! defined $ini) { die "Couldn't open $inifilename : $!\n"; };

Good advice: If you keep getting undefined errors/warnings, some variable wasn't properly initialized. This is an easy error, as you already know that something goes wrong, and Perl even tells you the line numbers. So always check your return values when initializing objects, opening files etc.

Replies are listed 'Best First'.
Re: Re: Problem with IniFile module
by stefan k (Curate) on Jan 31, 2001 at 15:09 UTC
    When you use the above code, Perl / your script will tell you that it couldn't find the .ini file. This is because you used single backslashes (\) to delimit the directories. This is wrong. Either use double backslashes, or, even better, use forward slashes, as both, Unix and DOS/Win32 understand these in a filename.

    Or -even better- use File::Spec->catfile(..) ...
    Regards
    Stefan K

    $dom = "skamphausen.de"; ## May The Open Source Be With You! $Mail = "mail@$dom; $Url = "http://www.$dom";