in reply to Dynamically Creating a Code reference

I don't know how you made that determination but I think something else is happening. The following code shows that the string only gets evaled with the ref itself is called.

use strict; use warnings; my $code = 'print "Hello\n"'; print "BEFORE\n"; my $test; $test->{a} = sub { eval $code}; print "BETWEEN\n"; $test->{a}->(); print "AFTER\n";

Outputs

C:\Perl\test>perl order_sub.pl BEFORE BETWEEN Hello AFTER

You can see the hello is only printed with the ref is executed and not when it is defined.


___________
Eric Hodges

Replies are listed 'Best First'.
Re^2: Dynamically Creating a Code reference
by Herkum (Parson) on Jun 16, 2006 at 13:06 UTC

    Your code works. I am still having a problem however because I am looking for the $dfv object to be passed to the sub {}. I find it passes the variable but it is not passing the DFV object.

    I hate trying to figure out these little quirks!