Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Initializing an anonymous hash

by Marshall (Canon)
on Mar 30, 2012 at 19:15 UTC ( [id://962671]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://962671]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found