Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Metadata and DBI Abstraction

by marcink (Monk)
on Jun 08, 2001 at 18:12 UTC ( [id://86907]=note: print w/replies, xml ) Need Help??


in reply to Metadata and DBI Abstraction

I'm afraid you'll need a separate block of validation code for each type, but it can be done very cleanly. Try a variation of the code below:

#!/usr/bin/perl -w use strict; my %validators = ( 'singleletter' => 'm/^[a-zA-Z]$/', 'integer' => 'm/^\d+$/', 'nottoolongstring' => 'length $_ < 10' ); sub check { my ( $type, $value ) = @_; my $v = $validators{$type}; return 0 unless defined $v; $_ = $value; return eval $v ? 1 : 0; } print check( 'singleletter', 'a' ) . "\n"; print check( 'integer', 'a' ) . "\n"; print check( 'nottoolongstring', 'a' ) . "\n";


-mk

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found