Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Type::Tiny 1.8.0 released

by haukex (Bishop)
on Dec 12, 2019 at 20:47 UTC ( #11110039=note: print w/replies, xml ) Need Help??

in reply to Type::Tiny 1.8.0 released

Thank you for this, I was just considering how I'd implement CSV input data validation in some code I'll be writing soon, and your post reminded me that I can do that with Type::Params :-)

Replies are listed 'Best First'.
Re^2: Type::Tiny 1.8.0 released
by tobyink (Canon) on Dec 12, 2019 at 23:38 UTC

    Hmm, yeah, sounds like an interesting use case.

    You might not even need Type::Params. The Tuple type from Types::Standard might be sufficient. Something like:

    use Types::Standard -types; my $row_type = Tuple[ Str, Str, Int, Bool, Optional[Num] ]; my $row_check = $row_type->compiled_check; while (my $row = $csv->get_line($fh)) { $row_check->($row) or die $row_type->get_message($row); }

    If you've got Type::Tiny::XS installed, and your row specification is simple enough, you might even find that $row_type was able to generate $row_check as an xsub. (Off the top of my head, I don't think the one in the example is, as I don't think Optional is implemented in XS yet.)

    If you end up with something cool, I would love to see and maybe incorporate it or something like it into the documentation.

      Thanks, good point! I'll probably be customizing some of the constraints, it's mostly numeric types (that can sometimes be NaN) where I want to code defensively and check that their length and precision isn't doing anything strange. This is for importing CSV files (measurement data from various dataloggers) to a database, and exporting them again, and I figured it'd be easier and more flexible for me to implement the detailed type constraints in Perl. If I run a benchmark, I'll let you know of the results!

Re^2: Type::Tiny 1.8.0 released
by Tux (Abbot) on Dec 12, 2019 at 21:06 UTC

    This and this are thw W3C thoughts on CSV validation. I did not yet find time to implement them.

    Enjoy, Have FUN! H.Merijn

      Very interesting, thanks!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11110039]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2020-12-01 03:22 GMT
Find Nodes?
    Voting Booth?

    No recent polls found