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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dynamically Creating a Code reference
by Herkum (Parson) on Jun 16, 2006 at 13:06 UTC |