
spire01
New User
Aug 22, 2011, 10:12 AM
Post #1 of 5
(1066 views)
|
|
Instance variable issue
|
Can't Post
|
|
Hi, I'm having a problem trying to access an instance variable in a singleton class I'm building. Here's a rough draft of what I've got: package customDB; my ($db) = 0; sub instance { unless ($db) { my ($class); $class = shift; $db = {}; bless $db, $class; } return $db; } sub function1 { my ($db, $name) = @_; return $db{$name} if exists $db{$name}; #THIS LINE return undef; } 1; The error when I try to compile: Global symbol "%db" requires explicit package name at ... Global symbol "%db" requires explicit package name at ... Any thoughts?
|