Label: Static-Info-1:: Static-Info-2:: Alternative:: Static-alt-Info-1 Alternative:: Static-alt-Info-2 #### # Sample Config File Label:perl-monks:perl-monks Hostname:perl-monks:www.perlmonks.org Description:perl-monks:The Perl Monks Webpage Alt:perl-monks:MonkVar-1 SomeSubVar-1 SomeVar-1-value Alt:perl-monks:MonkVar-2 SomeSubVar-2 SomeVar-2-value Label:ackers:ackers Hostname:ackers:www.ackers.net Description:ackers:Just my Page Alt:ackers:AckVar-1 SomeSubVar-1 SomeVar-1-value Alt:ackers:AckVar-2 SomeSubVar-2 SomeVar-2-value #### #!/usr/bin/perl # Here I will define all the static parts of the config file in an array # this is a nessesity, not only for easily adding features to your config # but to keep code changes down to a minimum :) my @carray = ("Label", "Hostname", "Description"); # pretend config.conf holds the information above hehe. open (CONF, "config.conf"); while () { s/\s+$//g; # remove whitespaces s/\s/ /g; # replace whitespace by space next if /^\s*\#/; # ignore comment lines s/\s*\#$//g; # ignore trailing comments next if /^\s*$/; # ignore empty lines ($one,$two,$three) = split(/:/); if ($one eq "Alt") { $alt = $one; $label = $two; $var = $three; foreach($three) { $$alt{$var} = "$label"; } } else { foreach ($one) { $$one{$two} = "$three"; } } } foreach $thing (keys %Label) { foreach $heh (@carray) { while ( ($k,$v) = each %$heh ) { print "Static Setting: $heh: $v\n" if ($k eq $thing); } } while ( ($k,$v) = each %Alt ) { print "Alternate Setting: $k\n" if ($v eq $thing); } print "\n"; }