in reply to Best Practice: How do I pass option parameters to functions?

TIMTOWT encapsulate globals... it depends on your future plans.

  1. If you have many subs which are supposed to react on "global" config settings you can always pass a hashref like already shown.

  2. Another approach is to have a dedicated package My_Config (which is effectively just a global hash, but doesn't pollute 'main::' anymore.

    Just set and read $My_Config::verbose

  3. The best (most radical) possibility to restrict the scope of variables are closures:

    { my $verbose; my $script; sub processDir { my $dir = shift @_; my $ret = qx($script $dir); chomp($ret); print qq(Output:"$ret"\n) if $verbose; } }

    nothing outside the outer block's scope can access them anymore.

    When needed you can also put getter() and setters() subs within this scope to change them dynamically.

  4. Saying this you realize that closures are just another way to think OOP, you are free to create a class Process and to realize the config settings as class attributes.

    But be aware that class attributes are only protected by convention, to make them really private one needs again closures... ;-) (update see also this reply)

HTH! =)

Cheers Rolf

( addicted to the Perl Programming Language)