Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: Type::Tiny 1.8.0 released

by tobyink (Canon)
on Dec 12, 2019 at 23:38 UTC ( #11110044=note: print w/replies, xml ) Need Help??

in reply to Re: Type::Tiny 1.8.0 released
in thread Type::Tiny 1.8.0 released

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.

Replies are listed 'Best First'.
Re^3: Type::Tiny 1.8.0 released
by haukex (Bishop) on Dec 14, 2019 at 20:58 UTC

    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!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2020-12-04 01:41 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (58 votes). Check out past polls.