Search code examples
sqlperldbisubroutine

Perl DBI Constants - how to access?


The documentation for getting type info includes this piece of suggested code for getting the mapping between code and integer:

foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) {
    printf "%s=%d\n", $_, &{"DBI::$_"};
}

But perl 5.16.2 won't allow it:

Can't use string ("DBI::SQL_GUID") as a subroutine ref while "strict refs" in use

I don't know how to turn off strict refs and I suspect it wasn't the author's intention that anyone do so. How can this subroutine call be accomplished?


Solution

  • You can turn off strict 'refs' by doing this

    {
        no strict 'refs';
        foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) {
            printf "%s=%d\n", $_, &{"DBI::$_"};
        }   
    }