[ABE.pm] My first enclosure doesn't work. :-(
Faber J. Fedor
faber at linuxnj.com
Fri Oct 26 10:30:50 PDT 2007
I'm porting a script to a webapp. One of the changes I want to do is to
dynamically generate an if-elsif. After thinking it through, it seems
like an enclosure would do what I want but I can't get it to work. :-(
I want to dynamically generate this from a hash:
if ($capt < 100)
{return (3.0);}
elsif (($capt >= 100) && ($capt < 250))
{return (1.5);}
...
elsif (($capt >= 10000) && ($capt < 50000))
{return (0.01);}
elsif ($capt >= 50000)
{return (0.005);}
In my enclosure, I generate my $stmt much as I would build an SQL
statement (yes, I know about DBIC; now get off my lawn!) so that, at the
end of the enclosure, if I 'print $stmt' I see a legit if-elsif
statement.
Now what? At the end of my enclosure, I say 'return sub { $stmt };' or
'return sub { eval($stmt) };'. If I then do a 'print
make_if_elsif(300)' I get 'CODE(0x8096228)' instead of the expected
'1.0'.
What am I doing wrong?
You can find my script at http://www.faberfedor.com/enclosure_example.pl
--
Regards,
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701
http://www.linuxnj.com
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the ABE-pm
mailing list