Home  |  Linux  | Mysql  | PHP  | XML
From:Steve Bertrand Date:Sat Jun 27 20:20:22 2009
Subject:Manipulating the symbol table
I've been reading quite a bit of docs the last few days, and in
"perltooc", I came across some neat tricks. Admittedly though, although
I understood it well enough to get excited about some of the techniques,
a reasonable portion of the details flew above my head (at this time).

One issue I've been dealing with is updating my modules with accessors,
instead of my applications using the instance variables directly.

In the mentioned perldoc, there are snips of code showing how to update
the symbol table to reference a subroutine with the same name as each
key in an object's hashref. In my case, it'd look something like this:

for my $datum (keys %User) {
no strict "refs";

*$datum = sub {
shift; # drop the caller
$User{$datum} = shift if @_;
return $User{$datum};
}
}

If I understand correctly, if I've done the above, and currently have this:

$user->{'username'} = 'steveb'; # in an app

I could then replace it instead with:

$user->username('steveb');

I'm not asking for a lack of trying. I'm just trying to ensure I
understand correctly so far, and if so, if I change my internal names, I
could then create 'alias' entries that point the old name to the new
instance variable.

Steve

Navigate in group perl.beginners at sever nntp.perl.org
Previous Next


Your recent visits



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants