What exactly do you want to test? The templating engine?
If you want to test a self-written templating engine, do yourself a favor and use an already tested one from CPAN: There is Template::Toolkit or the smaller Text::Template or Template::Simple. They should already be well tested
What do you want to do? Revert the config file to the template and compare? Or change the template to a config file and compare?
If you have the actual data that was used to create the config file, just use the second version and a different template package to create the same config file and compare
The first version on the other hand does not need the actual data. But your regex makes no sense:$mask_tmp =~ s/__REGEX__/[^\\n]+/g; (I repeat it here because you forgot code tags arround it in your post). You can't substitute __REGEX__ with a match expression. How should the machine know what you want to put in there.
If you meant $mask_tmp =~ s/[^\\n]+/__REGEX__/g; instead, it would replace anything, so lets change that to $mask_tmp =~ s/interface \(\n+/interface (__REGEX__/g;
The additional problem that you might have more interfaces in the filled in config file could be corrected with the following hacks for example:
1. Count lines that begin with interface in the config file and add lines appropriately to the template file.
2. Parse the config file line by line and match it against the template. This would mean "don't ever change your template or you have to edit your script too"
OR you could do a clean solution: Use a template library. Or if you are paranoid, use two and compare their output
In reply to Re: Template-based router configuration audit
by jethro
in thread Template-based router configuration audit
by ccie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |