in reply to Best practices for passing $dbh to subroutines

If lots of functions require the same parameter(s), think "objects". Just write a package that stores the DB handle. You can then have finer control over the possible actions (i.e., instead of $self->db->do('that'), you can define methods like $self->this; $self->that etc.)
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Best practices for passing $dbh to subroutines
by CountZero (Bishop) on Jan 26, 2014 at 16:21 UTC
    Of course, every method call gets implicitly the object as its first parameter. In this case the database handle is the explicit first parameter.

    Same same but different.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      I usually store the handle somewhere deeper in the object, with prepared selects or inserts around. So, the methods look like:
      sub add_numbers { my ($self, @params) = @_; $self->{insert_num}->execute(@params); } sub vacuum { my $self = shift; $self->{db}->do('vacuum'); }
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ