in reply to Eval errors though code is successful

Using eval for this kind of thing might be a little over the top. It works, yes, but being a dynamically compiled thing can cause problems. Personally, I would have implemented it without the eval. The code below is a little more "verbose", but most of it is standard issue variable declarations:
sub FindRecord { my ($self) = shift; my ($key) = @_; my $ref = \{$self->{$key}}; if (defined $ref->{path}) { my $path = $ref->{path}; foreach my $bit (@$path) { $ref = $ref->{$bit}; } } return $ref; } # ... sub SomeFunc { my ($self) = shift; # ... ${$self->FindRecord($key)} = $value; }
This, of course, could also be declared as an 'lvalue' function which would eliminate the ${} prefix. lvalue functions are fun, and I hope that they don't take them away any time soon.

NB: Code untested, used for demonstration purposes.

Replies are listed 'Best First'.
Re: Re: Eval errors though code is successful
by AidanLee (Chaplain) on Jul 09, 2001 at 16:13 UTC
    Nice approach. I was looking for something similar to this a while back when I first concocted the eval solution. Your particular example doesn't quite do what I need, but I can see how to get there from here. Thanks for the suggestions.