At work, I've been building a script that will wrap around system calls to provide OS-independent file actions. It provides the ability to use defined parameters (so that things like directory names are abstracted out) and a bunch of error handling. My client loves it.

The basic design is that it will take a filename and find a list of commands to execute. It then takes each command separately, resolves the parameters, then calls a Perl module to do the actual action. (File::Copy for copy and move, Net::FTP for ftp, etc.)

Some of the parameters it allows for are FILENAME, BASENAME, and EXT so that you can do something like:

copy,abcd.txt,[BASENAME].sav

Recently, my client asked me to provide the ability to back-references. This would allow the following:

copy,abcd.txt,efgh.txt,[BASENAME].sav compress,[2]

Not a problem, right? Well, I ran into a major issue. If I tried to resolve [2] before resolving [BASENAME].sav, my resolve code complained that [BASENAME] didn't exist. If I didn't, then how do I get [BASENAME] into [2]? Quite the conundrum ...

The solution ended up being that I needed to do my error-checking later. Do the resolutions in one sub, then check for unresolved parameters later. Much later. The error-checking code remained the same, just in a different place. (Coincedentally, it also cleaned up the resolution subroutine.)

Moral of the story? Your error-checking might be in the wrong place. Just because it doesn't deal with the standard execution path doesn't mean you can throw it in wherever you want.

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to The problem with design and error-handling by dragonchild

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.