On Mon, Oct 27, 2003 at 03:21:50PM -0700, Wiggins d Anconia wrote:
> > This is what I tried:
> > 
> > eval "use Tk";
> 
> I would have thought in this case you would want the BLOCK form of
> 'eval' rather than the EXPR form?  Or does it matter?  Gurus can you
> expound on the differences in this case?

Since use() happens at compile-time, this doesn't work the way it
ought to:

> eval { use Tk };
> if ($@) {
>   # module not ok, etc.
> }

Try it with a different module (one you don't have) and you'll
see the problem...  

You can see the same thing with BEGIN blocks:

  eval q{ BEGIN{ die 'Whoops!' }};   # string eval() catches error
  eval  { BEGIN{ die 'Whoops!' }};   # block eval() doesn't

String eval works here because the string is compiled (and executed)
at runtime, when eval() is called.  This means that compilation errors
will be protected by the eval().

Block eval doesn't work because the block is compiled (although it's
not executed) *before* eval() is called.  This means that compilation
errors aren't protected.

Since require() happens at run-time, the OP could do something like
this as well:

    BEGIN{ eval{ require Tk }};  # and optionally: Tk->import

-- 
Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to