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

I've been searching the code for both IniFile and Config::Ini for about a day now searching for the origin of this error.

perl -we "use Config::Ini;$ini = new Config::Ini('test.tmp'); $ini->pu +t(['temp']) or die($!);" Use of uninitialized value in exists at E:/Perl/site/lib/Tie/IxHash.pm + line 41. Use of uninitialized value in exists at E:/Perl/site/lib/Tie/IxHash.pm + line 47. Use of uninitialized value in hash element at E:/Perl/site/lib/Tie/IxH +ash.pm line 56. Use of uninitialized value in hash element at E:/Perl/site/lib/Tie/IxH +ash.pm line 56. No such file or directory at -e line 1.


I've been using IniFile (Both Config::Ini and IniFile fall apart similarly) for ages, but recently upgraded from 5.6.0 to 5.6.1. I've been unable to see any noticable change that can explain why this fails. I can give more information if necessary. I have attempted to use the debugger to trace it, but it doesn't seem to be working. (Could be the fact that I don't really know how to use the debugger...)

Thanks for any help or suggestions you can offer.


-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate

"Weird things happen, get used to it."

Flame ~ Lead Programmer: GMS

Replies are listed 'Best First'.
(tye)Re: Error with IniFile and Config::Ini
by tye (Sage) on Jan 14, 2002 at 21:56 UTC

    I checked the code and I think I see the problem. Both of the ini modules you mention use the exact same idiom that I would never use and it doesn't surprise me that a bug cropped up related to it:

    my $self = bless {}, $class; # Use an indexed hash to preserve the order. tie %{ $self->{sections} }, 'Tie::IxHash';
    which boils down to:     tie %{undef}, 'Tie::IxHash'; so I'd replace it with:     tie %{ $self->{sections}= {} }, 'Tie::IxHash';

    Sure, you could consider it a bug in Perl (especially since it used to work the other way), but I still consider it dangerous code to be avoided (depending on autovivification to kick in soon enough).

            - tye (but my friends call me "Tye")
      After changing al lthe code to match your reccomendation tie %{ $self->{sections}= {} }, 'Tie::IxHash';, it still doesn't work:

      perl -we "use IniFile; my $ini = new IniFile('test.tmp');$ ini->put(['test']) or die($!);" Use of uninitialized value in exists at E:/Perl/site/lib/Tie/IxHash.pm + line 41. Use of uninitialized value in exists at E:/Perl/site/lib/Tie/IxHash.pm + line 47. Use of uninitialized value in hash element at E:/Perl/site/lib/Tie/IxH +ash.pm line 56. Use of uninitialized value in hash element at E:/Perl/site/lib/Tie/IxH +ash.pm line 56. No such file or directory at -e line 1.


      I understand the No such file or directory complaint, (although I think it's rather unnecessary, why does -e set $! ?) I still don't understand where those warnings are coming from...


      -----BEGIN GEEK CODE BLOCK-----
      Version: 3.12
      GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
      PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
      ------END GEEK CODE BLOCK------
      Translate

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

Re: Error with IniFile and Config::Ini
by dmmiller2k (Chaplain) on Jan 11, 2002 at 18:38 UTC

    I'm unfamiliar with these modules in particular, but is it possible that after upgrading Perl you need to reinstall the modules, too?

    dmm

    If you GIVE a man a fish you feed him for a day
    But,
    TEACH him to fish and you feed him for a lifetime
      No, I deleted my old install before installing 5.6.1... It's the ActivePerl version. I used PPM to install IniFile and Config::Ini afterwards.

      Those errors make me think about Tie::IxHash though... is it possible the error is there? Both modules use it...


      -----BEGIN GEEK CODE BLOCK-----
      Version: 3.12
      GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
      PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
      ------END GEEK CODE BLOCK------
      Translate

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

Re: Error with IniFile and Config::Ini
by talexb (Chancellor) on Jan 12, 2002 at 21:43 UTC
    I'd recommend you go to the appropriate CPAN page (sorry, having trouble inserting a link, try http://search.cpan.org/doc/AVATAR/Config-Ini-1.08/Ini.pm ), print out the documentation on Config::Ini and read it. Then try a few examples, using a real script and not a one-liner.

    If a couple of the simple functions fail, then there may well be something wrong with your installation.

    I'm not perfect either -- I have resisted using the debugger, not because I'm lazy but because I'm a little reluctant to learn yet another debugger's cryptic commands. I took the plunge recently and while I am a little klutzy right now (you should have seen me the first year I used vi) I got the job done. <aside> Use the debugger religiously and "the truth shall set you free" -- paraphrasing, the debugger tells the truth to any whose ears are open. If you can't be bothered to use the debugger, it will most likely take you much longer to solve your problem.</aside>

    --t. alex

    "Of course, you realize that this means war." -- Bugs Bunny.

    ps When you ask a question on CB (like you did around 11am ET Saturday), it's considered a courtesy to stick around for an answer. :)

      I don't think the debugger could really have helped me here... I found the source of the error message (No such file or directory)... Theres a file test (-e) used in the open method in both of the modules. However, it doesn't explain those warnings from Tie:IxHash or the fact that $ini->put() returns false... Is there something wrong with Tie::IxHash's way of doing splice?

      Sample from the open sub:
      sub open { my ($self, $file, %args) = @_; if (defined $file) { $self->{file} = $file; } else { $file = $self->{file}; } # No need to do anything if this is a new file. return 1 unless(-e $file)



      -----BEGIN GEEK CODE BLOCK-----
      Version: 3.12
      GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
      PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
      ------END GEEK CODE BLOCK------
      Translate

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS