Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: DBI, $dbh, and subroutines

by LanX (Bishop)
on Jul 12, 2009 at 03:57 UTC ( #779304=note: print w/replies, xml ) Need Help??

in reply to DBI, $dbh, and subroutines

I'm an advocate of DRY, passing it around increases the error probability , e.g. typos.

OTOH globals tend to have a problem, if the line distance between creation and usage gets to big, or generally if scope and context are not easy to oversee.

I'd use a block scope to simulate an object², the "global" is used like a class-attribute.

{ my $global="whatever"; sub method1 { ...; foo($global); ... } sub method2 { ...; bar($global); ... } sub ... }

Closures are in most simple cases more elegant than objects, especially in perl¹!

(they just can't inherit, but that's not a "simple" case anymore).

Cheers Rolf


(¹) just compare to grandfathers lightweight object! No blessing, no $self ...

(²) "encapsulation" to be more precise

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://779304]
LanX passes the blame to jdpatches. ..
Eily the verb from this sentence
[LanX]: jdporter adjusted the best nodes algorithm not long ago to public demands, my theory more complicated= more error prone
[Eily]: what error? I see no issue :P
LanX and: = harder to reproduce. ..

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2018-03-20 10:18 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (249 votes). Check out past polls.