Okay, to make up for my snide reply a few minutes ago, I decided to whip this up for you. It should get you started as a rough guide for approaching your problem:
use strict; use Data::Dumper; my %hash; my $section = '__none__'; while (<DATA>) { next if /^#/; chomp; if ( /^\[([^\]]+)\]$/ ) { $section = $1; } elsif ( /^([^=]+?)\s*=\s*(.*)$/ ) { $hash{$section}{$1} = $2; } } die Dumper( \%hash ); __DATA__ # This is a configuration file. Section = none [TITLE] Name = John Location = USA [HEAD] Name = James Location = Canada [BODY] Name = Mayer Location = UK
Output:
$VAR1 = { 'TITLE' => { 'Location' => 'USA', 'Name' => 'John' }, 'BODY' => { 'Location' => 'UK', 'Name' => 'Mayer' }, '__none__' => { 'Section' => 'none' }, 'HEAD' => { 'Location' => 'Canada', 'Name' => 'James' } };
In reply to Re^3: .ini type file to store contents in hash of hash format
by edan
in thread .ini type file to store contents in hash of hash format
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |