LPM: Strict variable checking in classes?

David Hempy hempy at ket.org
Wed Mar 28 21:58:12 CST 2001


I'm delving into using some object oriented approaches in a perl program 
for the first time.  Finding some really neat tricks.

It seems that all instance variables (aka class attributes) are key/value 
pairs in an anonymous hash.  This makes it really easy to tote along from 
function to function all the variables you might possibly need.  Also 
really easy to create new instance variables on the fly...something that 
should make a C++ programmer absolutely giddy.  (or make them shudder...)

Anyway, one hitch I've run into is losing the "strict" checking of my 
variable names.  If I spend a bunch of work incrementing $count and then 
try to print $coutn, perl will fuss at me at compile time.  ("use strict" 
starts every program I write)

However, the laid-back approach of hash lookups will happily let me print a 
useless $this->{coutn} after incrementing $this->{count} a few thousand 
times.  Tracking down typos like that can be a real pain.  (And a 
shuddering C programmer now beams...)

Is this just the nature of the beast?  Are there other ways to handle 
instance variables in a class?  I fully expect to find the answer ten 
seconds after I send this message, so wish me luck.

-dave


ps. I've ordered the OOP book that several in the group have 
promoted...hope to have this program done before it gets here.

-- 
David Hempy
Internet Database Administrator
Kentucky Educational Television - Distance Learning Division
<hempy at ket.org> -- (859)258-7164 -- (800)333-9764





More information about the Lexington-pm mailing list