# Walk the hash of complex data structures called $macros # and $rules. # starting the traversal of %$rules while ( my ($rule_key,$rule_val) = each(%$rules) ) { # Now, breaking out the hash references from $rule_val while ( my ($nkey,$nval) = each(%$rule_val) ) { # Simple enough, if the key is "macro" then we have found # our macros in the complex data structure. if ( $nkey eq "macro" ) { # Now, we need to start to traverse the %$macros structure # and we will do the merge. while ( my ($macro_key,$macro_val) = each(%$macros) ) { # Now, walk the array reference that was contained in the # reference $nval (which is a reference to an array) for ( @$nval ) { # Now, if the key from the macro hash matches the # rule that is referencing a macro then... if ( $macro_key eq $_ ) { # Replace the macro name with the actual regex from the # macro. map { push(@{$$rules{$rule_key}{regex}},$_); } @{$$macros{$_}{regex}}; # Now that we have the macros mapped to the rules # we can drop the macros from the rules hashes # since they are dead weight now anyway.. delete(%{$rule_val}->{macro}); } } } } } }