#!/usr/local/bin/perl -w use strict; use Env; my $file = "$HOME/archive_bin/configs/dtfr_archiver.conf"; my ($class,$type,$var,$rval,%config); my (@rule,%macro,%rule); open(F,$file) or die("Can't open it: $!\n"); while ( ) { chomp; my $current_line = $_; my $ok = "^(macro|define|rule)"; next if ( /^#/ ); # skip comments next if ( /^\n/ ); # skip newlines and all only-spaces my $check = (/$ok(\s+\w+\s+\{)?/ .. /^\}/); do { if ( $check == 1 ) { $class = $1; $2 =~ /^.*? (\w+)\s+\{/ if $2; # do more checking here $type = $1; # do more checking here next; } if ( $check !~ /E0/ and $check > 1 ) { if ( $current_line =~ /=/ ) { ($var,$rval) = split(/=/,$_); $var =~ tr/ //d; $rval =~ tr/" ;//d; if ( $rval =~ /,/ ) { my @rval = split(/,/,$rval); } } if ( $var and $rval ) { # Ok, create an array. my @rval = split(/,/,$rval); # Create a reference to that array. my $rval = \@rval; # Create a hash of hash references pointing to the array reference for the # macros. print "type: $type => var: $var -> val: ".join(", ",@$rval) ."\n"; $macro{$type} = { $var => $rval } if ( $class eq "macro" ); # Do the same for the rules. $rule{$type} = { $var => $rval } if ( $type =~ /^\d+$/ ); } } } if $check; } print "Keys for \%macro: ".join(", ",keys(%macro))."\n"; while ( my ($key, $val) = each(%macro) ) { print "key: $key => vals:\n"; while ( my ($nkey, $nval) = each(%$val) ) { for ( @{$nval} ) { print "\tkey: $nkey -> val = $_\n" if ( $nkey ); } } }