in reply to Re^2: trouble with evaluate
in thread trouble with evaluate

What "dire warnings" about using our?

Also, you claim that the below parse function works. How does it actually "work"? What do you believe that you're saving in $self->{$var1} and how are you planning on using it?

my $var1; my $var2; my $var3; #set values -- this part works sub parse{ ... $self->{$var1} = 'a'; $self->{$var2} = 'b'; $self->{$var3} = 'c'; ... }

If you're doing true Object Oriented programming, I believe that what you truly want is just the following

package parser; ... # Some constructor here ... #set values -- this part works sub parse{ ... $self->{var1} = 'a'; $self->{var2} = 'b'; $self->{var3} = 'c'; ... } sub get_var{ my ($self, $var_name) = @_; return $self->{$var_name}; }

Replies are listed 'Best First'.
Re^4: trouble with evaluate
by genghis (Novice) on Apr 09, 2011 at 02:53 UTC

    Thank you for the suggestion. I tried to implement it, but can't figure out what you would pass in to the get_var() method. I tried a simple string, but I always get "undef" back, even with the versions of "eval" syntax suggested by Eliya.