in reply to Printf in perl / Lazy hash possible?

This is trivial. Store a delayed computation.

%hash = ( key => sub { value() } );

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: Printf in perl / Lazy hash possible?
by EvanCarroll (Chaplain) on Sep 03, 2007 at 07:47 UTC
    This is actually the conclusion that I arrived at too, but it seems ugly. I'll post again, and present this as a "How would you write the following code".


    Evan Carroll
    www.EvanCarroll.com

      It's only ugly because you're using perl. If you were in another language where you were used to seeing "lambda" all the time in user code it'd be ordinary. If you were using Haskell you wouldn't even have to be explicit about it. Since you're using Perl, you've got to live with what you've got. Or enact dizzying schemes of fantastic magicalism. I hope all that machinery is worth it just to get rid of the sub { ... }.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊