I may be approaching this a little simplisticly, but I do not usually think of using a function reference as eval'ing ( pardon me while I make up a few words ).
The reason eval $x; doesn't "work" is that you are using
a reference in scalar context, which has the well defined
behaviour of stringifying the reference. I like this feature - it makes it easy to figure out how to access information deep withing a complex data structure.
The $x->() format tells perl to dereference instead of stringify. This is again a standard syntax in perl.
$x->{foo} access that key from a hash reference. Similarly from an array reference. Why do you expect a different syntax simply because it is a function reference?
eval is there for two purposes:
- Roughly equivalent to "try/catch" in other languages.
This allows me to do something potentially fatal ( like use
a module that doesn't exist ) without hurting myself. I most often use this construct in DBI code when I need to
roll back a transaction if it fails.
- To run code generated at runtime. Personally, I haven't yet had the need to use eval in this form, but I am certain other monks can expand on this point.
I am not a perl fanatic. I fully recognize each language has its purpose. I have never used lisp in any sense other than a college class, but I thought it was pretty fun. If you understand lisp better than perl, and it does the job you need, than by all means use it.
Comparing one language to another seems pretty useless to me - each language is designed to solve a unique problem space. Would you also claim that a hammer is better than a screw driver? I guess I am asking, with respect, what the point of this node was?
mikfire
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.