in reply to Supplying a value for an undefined variable

My solution assumes and requires that the variable name within the code is followed directly by a semi-colon. To test out my example, run it with the my $foo = 'hi'; declaration, then comment that line out. Good luck.

#!c:/perl/bin/perl -w use strict; my %data = ( 'bar' => { 'code' => 'print $foo;', 'values' => { 'foo' => 'hello' } } ); my $foo = 'hi'; eval $data{bar}{code}; if ($@) { $data{bar}{code} =~ s/\$([^;]+);/\$data{bar}{values}{$1};/g; eval $data{bar}{code}; }