in reply to Showing why a Regexp didn't match
may be re-written as:$input->{$key} =~ /[\<\>\:\"\|\?\*]/; die "Error, found $&";
$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:
By including the offending path in the output it should be easy for the user to tell what the problem is.die "Invalid path: $input->{$key}\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Showing why a Regexp didn't match
by hipowls (Curate) on Apr 12, 2008 at 02:05 UTC |