in reply to Re: Brannigan: hash validation
in thread Brannigan: hash validation
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Brannigan: hash validation
by henzen (Acolyte) on Feb 15, 2018 at 10:03 UTC | |
This looks like it will work - I've been able to figure out most from the docs (I really wish module creators would have real-life examples, but anyway). Is there a way to do an array count validation?:
I'd appreciate any pointers. Thanks Edit: Figured out regex - use StrMatch[] Edit 2: Validating array count can be done with an anon sub, but it then kills the other check:
So I guess the question is how to combine those two checks (without having to hand code the num=>Int checks in pure Perl of course). | [reply] [d/l] [select] |
by 1nickt (Canon) on Feb 15, 2018 at 13:47 UTC | |
Hi again, First, be sure to check Type::Params for a more user-friendly way to use the types and type libraries you create (and the standard ones) in validating parameters to a function. Second, be sure to review all the docs, including the cookbooks. There's actually quite a lot, just not well collated centrally. You'll also find good examples in the archives of the Perl Advent Calendar. Type RegexpRef tests only whether it is passed a compiled regexp, i.e. with qr//, not the content of the regexp. Use StrMatch for that. You can always declare your own types, as well as your own type library. Here I declare a type that requires an array ref, and that it be of a certain length. Output:
Hope this helps!
The way forward always starts with a minimal test.
| [reply] [d/l] [select] |