Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

IniFiles

by strictvars (Sexton)
on Apr 12, 2005 at 19:16 UTC ( [id://447142]=CUFP: print w/replies, xml ) Need Help??

I didn't notice Scott Hutton's Config::IniFiles, and just want to share it anyway.

Put the inputs into a HASH.
HASH values modification is forbidden.
Blanks are cool.
Perl comments (#) are also cool.

use ModestIniFile; my %addresses; tie %addresses, ModestIniFile, 'addresses.ini';
package ModestIniFile; use strict; sub die_msg{ ' at ' .( join ' line ', @_[1,2] )."\n" } sub TIEHASH{ my ($class, $file) = @_; open IN, $file or die "File $file does not exist!".die_msg caller; my %ini = map{ split /\s+:\s+/ } grep !/^\s*$/ && !/^[ \t]*#/, <IN +>; bless [ sub{ $ini{ $_[0] } }, sub{ keys %ini }, sub{ each %ini }, +sub{ scalar %ini }, sub{ undef %ini } ], $class } sub FETCH{ $_[0][0]->($_[1]) } sub STORE{ die "Illegall attempt to store INIHash ".die_msg caller } sub DELETE{ die "Illegall attempt to delete from INIHash ".die_msg cal +ler } sub CLEAR{ die "Illegall attempt to clear INIHash ".die_msg caller } sub EXISTS{ $_[0]->FETCH($_[1]) } sub FIRSTKEY{ &{ $_[0][1] }; &{ $_[0][2] } } sub NEXTKEY{ &{ $_[0][2] } } sub SCALAR{ &{ $_[0][3] } } sub DESTROY{ &{ $_[0][4] } } 1;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-19 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found