Data::Default -- Small utility for getting the default value of an argument or variable.
use Data::Default ':all'; # variables my ($var); # later... if (default $var, 1) { # stuff if the $var is undef or set to a true value } else { # stuff if the $var is defined and set to true }
Just a little utility for getting the default value of an argument or parameter. All it really does is accept an array of arguments, then return the first argument that is defined.
This function is usually used in a subroutine to get the default value of a parameter. A typical usage would be in a subroutine like this:
sub mysub { my (%opts) = @_; if (default $opts{'some-option'}, 1) { # do stuff some-option was sent and was true or was not sent } else { # do stuff some-option was sent and was false } }
You might prefer to use Attribute::Default by Stephen Nelson which provides similar functionality.
Attribute::Default
String::Util can be installed with the usual routine:
perl Makefile.PL make make test make install
Copyright (c) 2010 by Miko O'Sullivan. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This software comes with NO WARRANTY of any kind.
Miko O'Sullivan miko@idocs.com
Initial release
Fixed bug: Exporter was not being loaded.
To install Data::Default, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Default
CPAN shell
perl -MCPAN -e shell install Data::Default
For more information on module installation, please visit the detailed CPAN module installation guide.