'eval' is an extremely powerful and dangerous construct, used in the wrong hands. One of the coolest things about it is that it can make an application (or Perl iteself) extensible, similiar to Forth.

Imagine a situation where you have a graphical calculator written in Perl. It has four basic functions: add, subtract, divide, multiply. You have a few extra buttons that users can assign functions to. By allowing them to enter an expression, you can create functions that previously didn't exist. You capture the user's function to a string, then 'eval' the string when it's time to use that key in a an expression. You've now extended the function of the calculator.

It's somewhat slow, since the 'eval' is done at run time instead of compile time, but it can be a neat way to implement otherwise difficult things. Of course, the peril should be obvious. You allow a user to enter something like`rm -rf /`eval that, and they've wiped the hard drive. Any input from users that's fed through 'eval' has to be fully qualified.

In Forth, you can do something that's even more powerful. The words you create become part of the language itself. You can create new words at compile time, or during run time. You think Perl obfusication can be hairy, try seeing some Forth that produces Forth code, compiles itself, runs itself, and then reproduces itself.

--Chris

In reply to (jcwren) Re: help with a Perl term by jcwren
in thread help with a Perl term by zdog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.