Hash or List to constructors

Rob rob at cowsnet.com.au
Sun Jun 30 18:27:38 CDT 2002

G'Day Scott,

> My preference for simple constructors (eg: DBI) is to hand just one 
> parameter. But for complex entries (eg: DBI options) it is 
> best to use a 
> hash, or even a hash ref.

I usually go the way of a hash/hashref for complex constructors, as I
feel this offers a more intuitive model rather than an order list of
values.  I mentioned hash/hashref as I often do something like this ...

sub foo {

    my %options;
    if (ref $_[0] eq 'HASH') {
        %options = shift;
    } else {
        if (scalar(@_) % 2) {
            %options = @_;
        } else {
            croak( 'Uneven number of arguments passed to foo - Argument
should be a hash or hash reference' );


Rob Casey
Business Manager, Senior IT Consultant
Cowsnet Internet and Professional Services

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3222 bytes
Desc: not available
Url : http://mail.pm.org/archives/melbourne-pm/attachments/20020701/70596a4f/smime.bin

More information about the Melbourne-pm mailing list