I found that testing helps a lot, and still I don't really test many of my perl scripts.

What helped is to move the functionality to modules, because IMHO modules are much neater to test than scripts.

So I started to write modules that do 95% of the work, and the scripts that use these modules just do some command line processing, but no real logic.

And yes, often I write the tests first. That's especially useful if you have a small, complex piece of code. Like a recursive regex that parses nested constructs.

Then you can build a basic regex, run the tests, refine it, run the tests, ... until you're done. And you don't fall into the trap of modifying something and getting what you want, but having undetected side effects. (At least you're not trapped that easily ;)

In reply to Re: Does anybody write tests first? by moritz
in thread Does anybody write tests first? by amarquis

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":