in reply to Coderef from scalar.

I wouldn't use an eval, if it's not necessary.

perl -e '$code = sub{ print "Ovid is a blowhard\n" };&$code'

This is better because your code is checked at compile time and you don't reinvoke the Perl interpreter.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid) Re: Coderef from scalar.
by vaevictus (Pilgrim) on Dec 29, 2001 at 05:10 UTC
    Defined as the problem, I *must* use a scalar full of code.

      This is often true, so I can understand why an eval might be necessary. What, exactly, is the source of the scalar? Is this being built at runtime? If so, eval might be the answer. If it's a bunch of static code snippets that can be determined at compile time, a hash of coderefs is faster and safer.

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

        yes ... it's part of a programmable IRC bot, using Net::IRC.
        the "special function" is Net::IRC::Connection->add_handler();
        so, yes, it's getting the code at runtime...

        I'm wanting to implement a ircbot with features similar to Everything(tm).