Saturday, 28 September 2013

Perl variable scoping issue

Perl variable scoping issue

I have a scoping problem in Perl. I have a global has called member. I
call a function and can display a property (password) of an object in the
hash. But when I try and get to this password property from the calling
sub it is not defined (although the object does exist).
Here's the code:
my($userid) = @_;
my($guid);
$guid = SQL->new($MembersTable,'userid');
$guid->where('userid');
$guid->columns('userid','password');
# error($member{$userid}{'password'});
%member = (%member, $guid->select($userid));
# $member{$userid}{'password'} = 'test';
guid has a property called password. If I print it out at the first
commented line I can see the value, In the calling sub it has now value.
If I set the property by commenting out the second line I can get to the
value in the calling sub.
I am obviously missing something pretty basic, but what is it?!

No comments:

Post a Comment