in reply to Re: .ini type file to store contents in hash of hash format
in thread .ini type file to store contents in hash of hash format

Hi,
Thanks for your reply.
Without using any module, how can i store the data.
Waiting for your reply
Thanks
  • Comment on Re^2: .ini type file to store contents in hash of hash format

Replies are listed 'Best First'.
Re^3: .ini type file to store contents in hash of hash format
by edan (Curate) on Aug 29, 2004 at 13:37 UTC

    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' } };
    --
    edan

Re^3: .ini type file to store contents in hash of hash format
by edan (Curate) on Aug 29, 2004 at 13:17 UTC
    Hi,
    Thanks for your reply.
    Without showing us your code, how can you expect us to help you.
    Waiting for your reply
    Thanks
    --
    edan

Re^3: .ini type file to store contents in hash of hash format
by ccn (Vicar) on Aug 29, 2004 at 13:31 UTC