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

#!/usr/bin/perl use strict; use warnings; use Config::IniFiles; my ( %ini_file, $ini_sect ); tie %ini_file, 'IniFiles', ( -file => "file1.txt"); foreach $ini_sect ( keys %ini_file ) { %$ini_sect = %{ $ini_file{$ini_sect} }; }
I am getting this error while running the above script "Can't locate object method "TIEHASH" via package "IniFiles" at ./ReadSGtest.pl line 7."

Replies are listed 'Best First'.
Re: Can't locate object method "TIEHASH" via package "IniFiles"
by Anonymous Monk on Mar 14, 2016 at 08:04 UTC
    tie %ini_file, 'IniFiles', ( -file => "file1.txt");

    should be

    tie %ini_file, 'Config::IniFiles', (-file => "file1.txt");

    Also, the line %$ini_sect = %{ $ini_file{$ini_sect} }; won't work under strict, since $ini_sect is a string and can't be used as a hash reference. But I'm assuming your code example is just a test and you'll be fixing that anyway.

Re: Can't locate object method "TIEHASH" via package "IniFiles"
by marto (Cardinal) on Mar 14, 2016 at 08:05 UTC

    Try replacing:

    tie %ini_file, 'IniFiles', ( -file => "file1.txt");

    with:

    tie %ini_file, 'Config::IniFiles', ( -file => 'file1.txt' );

    from the module documentation.