DBI Utility Functions

DBI provides a few utility routines that can be used for testing or printing values. These functions are invoked as DBI::func_name(), rather than as DBI->func_name().

  • @bool = DBI::looks_like_number (@ary);

    Takes a list of values and returns an array with one member for each element of the list. Each member indicates whether the corresponding argument looks like a number: true if it does, false if it doesn't, and undef if the argument is undefined or empty.

  • $str = DBI::neat ($value [, $maxlen]);

    Returns a string containing a nicely formatted representation of the $value argument. Strings are returned with surrounding quotes; numbers are not. (But note that quoted numbers are considered to be strings.) Undefined values are reported as undef, and unprintable characters are reported as '.' characters. For example, if you execute the following loop:

    for my $val ("a", "3", 3, undef, "\x01\x02") 
    {
        print DBI::neat ($val) . "\n";
    }
    

    The results will look like this:

    'a' 
    '3'
    3
    undef
    '..'
    

    The $maxlen argument controls the maximum length of the result. If the result is longer than $maxlen, it is shortened to $maxlen?4 characters and "...'" is added. If $maxlen is 0, undef, or missing, it defaults to the current value of $DBI::neat_maxlen, which itself has a default value of 400.

    Don't use neat() for query construction; if you need to perform quoting or escaping of data values to be placed into a query string, use placeholders or the quote() method instead.

  • $str = DBI::neat_list (\@ary 
                           [, $maxlen
                           [, $sep]]);
    

    Calls neat() for each element of the list pointed to by the first argument, joins them with the separator string $sep and returns the result as a single string.

    The $maxlen argument is passed to neat() and thus applies to individual arguments, not to the combined result of the neat() calls.

    If $sep is missing, the default is ", ".