Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: hash reference

by strat (Canon)
on Feb 06, 2002 at 14:32 UTC ( [id://143623]=note: print w/replies, xml ) Need Help??


in reply to hash reference

I'd parse it in the following way... (haven't tested)
sub ReadIniFile { my ($iniFile) = @_; my %config = (); local ($/) = undef; unless (open (INI, $iniFile)){ print (LOG "Error: couldn't read from INI $iniFile: $!\n"); die ("Error: couldn't read from INI $iniFile: $!\n"); } my $ini = <INI>; close (INI); my (@mainpoints) = ($ini =~ /(\[\w+?\])\n/g); # extract [.....] my ($x, @contents) = split(/\[\w+?\]/, $ini); @config{@mainpoints} = @contents; foreach (keys %config){ my %subHash = (); my @values = split(/\n+/, $config{$_}); foreach (@values){ my ($key, $val) = split(/\s*\:\s*/, $_, 2); next unless defined $key; next if $key eq ''; next if $key =~ /^\s*\#/; $subHash{lc($key)} = $val; } $config{$_} = \%subHash; } return (\%config); } # ReadIniFile

Best regards,
perl -e "$_=*F=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-03-19 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found