in reply to Using a 'getopt' in module code

If you're up to 13 options, and most of them are not used together, its time to be nice to the users by providing a higher level interface to function that takes care of most of those details. You can curry the function.

Each wrapper function represents a particular way of calling the general function so the programmer doesn't have to know about all of the other options. They just know what they want to acccomplish and the wrapper function takes care of the other details. If you change the general function, the programmer doesn't really care as long as the wrapper functions still do their work correctly.

sub general_function_with_lots_of_args { ... } sub do_it_with_name { general_function_with_lots_of_args( undef, undef, $_[0], undef, .. +. ) } sub do_it_using_id { general_function_with_lots_of_args( undef, $_[0], undef, ... ) } sub do_it_this_way { ... } sub do_it_that_way { ... }

As for the various Getopt modules, there are indeed quite a few. However, there are quite a few ways that programs take command line arguments too. I talk about some of these in my configuration chapter in Mastering Perl.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

Replies are listed 'Best First'.
Re^2: Using a 'getopt' in module code
by throop (Chaplain) on Dec 04, 2006 at 16:52 UTC
    Thanks for the several good replies. Clearly from reading them, my better approach is to pass the function arguments as a hash. I think you've saved me from writing some truly crufty code.

    And thanks for the ideas about the various Getopt modules.

    throop