Generally you should avoid using $', $& and $'. Once they appear in your program they slow down all regular expression calls. You can achieve the same functionality by specifying your own captures, i.e.
$input->{$key} =~ /[\<\>\:\"\|\?\*]/; die "Error, found $&";
may be re-written as:
$input->{$key} =~ /([\<\>\:\"\|\?\*])/; die "Error, found $1";
Am I doing it right? The ^a-zA-Z?:? is at the beginning as paths my be full windows paths. Although I get the feeling I problem mean ^(a-zA-Z:)?
I think you'll want ^([a-zA-Z]:)?. It depends on if :\some\path is a valid path (i.e. a leading colon without a drive letter.)

The final method you've come up with is about the best you can do. For each error message that you can emit you have to develop a test for it. The only problem I see is that another way your validation test can fail is if there are no valid characters after the "drive:" prefix, e.g. "C:". In that case you'll want a different error message.

Honestly, I don't see what's wrong with just saying:

die "Invalid path: $input->{$key}\n";
By including the offending path in the output it should be easy for the user to tell what the problem is.

In reply to Re: Showing why a Regexp didn't match by pc88mxer
in thread Showing why a Regexp didn't match by cosmicperl

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.