in reply to Ways of Passing Configuration Parameters

My preference is a single hash ref for options with an explicit "1" for Boolean options: subr( { this=>1, that=>[ 5, 6 ], other=>'/path/etc/foo' } )

I prefer the hash ref for several reason. It requires the caller to put in the { and } which let's Perl catch if they put in a odd number of arguments. It fits in well with routines that have some required arguments besides the hash options. It makes it easier to extend the interface in the future. One routine can just pass the same options along to another without any copying involved. It makes validating the passed-in arguments easier [just UNIVERSAL::isa($opts,"HASH")]. It forces your code to not depend on the order in which the options are listed.

One disadvantage is that you should be careful to avoid having your routine modify the ref'd hash.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Ways of Passing Configuration Parameters
by John M. Dlugosz (Monsignor) on Jun 09, 2001 at 02:04 UTC
    I like that, and is one I'm considering, because the configurer will type the same kind of structure that the callback gets. But I'm expecting most things to have no arguments, so I don't like needing the arg.

      Well, another advantage I've found with this is that you can make changes more easily in many cases because: subr( { ..., debug=>0, ... } ) is often a smaller change than having to drop or insert an argument. (:

              - tye (but my friends call me "Tye")