TStanley has asked for the wisdom of the Perl Monks concerning the following question:

I am just testing out some modules, to better improve my understanding of them. I am running ActiveState Perl, Build 623 on a Windows 95 machine.
#!C:\Perl\bin\perl -w use strict; use Digest::MD5 qw(md5_hex); use IniFile; use Term::ReadKey; my $login=""; my $password=""; my $encryption = Digest::MD5->new; my $ini = new IniFile('C:\Downloads\Perl\test.ini'); print"\n"; print"Login: "; $login=<STDIN>; chomp($login); print"\n"; print"Password: "; ReadMode 2; $password = <STDIN>; chomp($password); ReadMode 0; print"\n"; $encryption->add($password); $password = $encryption->hexdigest; my $logincheck = $ini->exists(['User','UserId',$login]); my $passcheck = $ini->exists(['User','Password',$password]); if($logincheck&$passcheck){ print"UserId/Password Entered\n"; } else{ $ini->put(['User','UserId',$login,-add]); $ini->put(['User','Password',$password,-add]); $ini->save(); }
The problem is when I actually add a new UserId and password to the .ini file, I receive the following warning several times:
Use of unitialized value in concatenation (.) at C:/Perl/site/lib/IniF +ile.pm line 280, <STDIN> line 2.
Any suggestions would be appreciated.

TStanley
In the end, there can be only one!

Replies are listed 'Best First'.
Re: Problem with IniFile module
by Corion (Patriarch) on Jan 31, 2001 at 12:22 UTC

    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.

      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";