#! /usr/bin/perl -w use strict; my %data; %data = ReadConfig("legacy.ini"); foreach my $value (values %data){ print "$value\n"; } print "$data{MAIN}\n\n"; sub ReadConfig { my $ConfigFile=shift; my %Config; my $Item; my $Value; open CONFIG,"<$ConfigFile" or die("Cannot open Config File!"); while() { chomp; next if ((/^#/)||(/^\s*$/)); if (/^\[(.*)\]$/) {$Item=$1;next;}; if($Item) { my ($SubOption,$Value)=split /\=/; if ($Value) { print "$Item\t$SubOption\t$Value\t"; $Config{$Item}{$SubOption} = $Value; print "-->$Config{$Item}{$SubOption}\n"; } else { $Config{$Item} = $_; } } } close CONFIG; foreach my $value (keys %Config){ print "->$value\n"; } return %Config; }