Quantcast
Channel: In Perl, how can I concisely check if a $variable is defined and contains a non zero length string? - Stack Overflow
Viewing all articles
Browse latest Browse all 10

Answer by daotoad for In Perl, how can I concisely check if a $variable is defined and contains a non zero length string?

$
0
0

The excellent library Type::Tiny provides an framework with which to build type-checking into your Perl code. What I show here is only the thinnest tip of the iceberg and is using Type::Tiny in the most simplistic and manual way.

Be sure to check out the Type::Tiny::Manual for more information.

use Types::Common::String qw< NonEmptyStr >;if ( NonEmptyStr->check($name) ) {    # Do something here.}NonEmptyStr->($name);  # Throw an exception if validation fails

Viewing all articles
Browse latest Browse all 10

Trending Articles