in reply to Initializing an anonymous hash

Another approach is to just use one of the configuration modules, like perhaps Config::Tiny. This avoids the "execute user editable code" problems of eval and folks are familiar with the format. Its just 2 lines of code for the basics..

#!/usr/bin/perl -w use strict; use Config::Tiny; use Data::Dumper; my $Config = Config::Tiny->read( 'configfile.txt') or die " $!"; # $Months here is a ref to a hash # my $Months = $Config->{Months}; print Dumper \$Months; =prints $VAR1 = \{ 'Month1' => 'January', 'Month2' => 'February' }; =cut __END__ #file configfile.txt contains this comment and this data #Sample Configuration File [Months] Month1 = January Month2 = February [Another_Section]

Replies are listed 'Best First'.
Re^2: Initializing an anonymous hash
by Anonymous Monk on Mar 31, 2012 at 07:51 UTC
    Thanks to everyone for the wisdom. I have enough material now to make relatively wise choice of implementation for what I am trying to do.