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

Config::IniHash, Config::IniFiles

  • Comment on Re: .ini type file to store contents in hash of hash format

Replies are listed 'Best First'.
Re^2: .ini type file to store contents in hash of hash format
by Anonymous Monk on Aug 29, 2004 at 13:13 UTC
    Hi,
    Thanks for your reply.
    Without using any module, how can i store the data.
    Waiting for your reply
    Thanks

      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

      Hi,
      Thanks for your reply.
      Without showing us your code, how can you expect us to help you.
      Waiting for your reply
      Thanks
      --
      edan