[ABE.pm] My first enclosure doesn't work. :-(

Faber J. Fedor faber at linuxnj.com
Fri Oct 26 16:45:06 PDT 2007


On 26/10/07 18:13 -0400, Ricardo SIGNES wrote:
> * "Faber J. Fedor" <faber at linuxnj.com> [2007-10-26T13:30:50]
> > 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?
> 
> Well, for one thing, you're even considering using string eval. :)

But you guys use it all the time!

> This code does *not* dynamically generate an if/else tree.  Basically, in
> dynamic Perl, you Just Don't Do That.  if/else trees are literal structures,
> and you'd have to generate code and then eval it.  

That's what I was trying to do. I wanted a function to write a function
as mentioned in the first paragraph on Chapter 7 of HOP.

> This is a red flag the size of Texas.  

Can you explain the concept of "code writing code" or "programs writing
programs" then cuz I'm WAY off base. 

> Instead, you'd build a data structure that can serve as a kind of
> dispatch table, 

I started down that route and ended up with the two-liner that I showed
Walt.

I'll look over your code and see what I can grok cuz I'm still trying to
write my first practical closure.

For the record, I didn't write the original if-elsif, but I am
refactoring it out of the production code.


-- 
 
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