Util::Utl - Scalar::Util, List::Util, List::MoreUtils, String::Util & more (via one subroutine)
version 0.0011
use Util::Utl; utl->first( { ... }, ... ) if ( utl->blessed( ... ) ) { } if ( utl->looks_like_number( ... ) ) { }
Util::Utl exports a single subroutine utl which provides access to:
utl
Scalar::Util
List::Util
List::MoreUtils
String::Util
Util::Utl also provides some additional functionality
Each function here is accessed in the same way:
utl->$name( ... )
Returns true if $value is undefined or has 0-length
Returns true if $value is undefined or is composed only of whitespace (\s)
List::Util::first
%hash = ( a => 1, b => 2, c => 3 ) ... = utl->first( \%hash, qw/ z a b / ) # Returns 1
For each name in @query, test $hash to see if it exists. Returns the value of the first entry found
@query
$hash
Returns undef if none exist
$options (a HASH reference) are:
exclusive True to throw an exception if more than 1 of query is present in $hash %hash = ( a => 1, b => 2, c => 3 ) ... = utl->first( \%hash, qw/ a b /, { exclusive => 1 } ) # Throws an exception (die) ... = utl->first( \%hash, qw/ a z /, { exclusive => 1 } ) # Does not throw an exception test A subroutine for testing whether a value should be included or not. Can be used to skip over undefined or empty values %hash = ( a => undef, b => '', c => 1 ) ... = utl->first( \%hash, qw/ a b c /, { test => sub { defined } } ) # Returns '' empty True to return an empty list instead of undef if none are found %hash = ( a => 1 ) ... = utl->first( \%hash, qw/ z x y / ) # Returns undef ... = utl->first( \%hash, qw/ z x y /, { empty => 1 } ) # Returns ()
Robert Krimen <robertkrimen@gmail.com>
This software is copyright (c) 2011 by Robert Krimen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Util::Utl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Util::Utl
CPAN shell
perl -MCPAN -e shell install Util::Utl
For more information on module installation, please visit the detailed CPAN module installation guide.