in reply to Re^4: Mr. Ternary is greater than Mrs. If Else
in thread Mr. Ternary is greater than Mrs. If Else
"\&" - is used while bullet proofing a program because it permits runtime error to exit my program so sudden. so the programmer could easily notice the error."eval" - is used when you have finished bullet proofing a program. well it just trap runtime errors that was not caught by the programmer.
<update>
No, the difference is that \& { } constructs a reference to a subroutine which is named after whatever it is the evaluation of the contents of { } returns. That is, \& {chr(65)} returns a reference to the subroutine A, be this sub defined or not. In your example, a subroutine is allocated in the symbol table named after the return value of exit or yes\n, depending on the input. Which is a weird form to shoehorn something into the symbol table.
</update>
<No, the difference is that \& { } constructs a code reference from a block (which isn't even a subroutine, just a code reference) which is a reference to a subroutine , while eval { } ... well, evals the { } block. So, \& { } is just bare metal, without the additional features eval { } provides.
One could say \& { } is to eval { } what do is to require, if that helps (it's not quite so).
I don't know the compile time implications of \& { }, but I suspect them to be the same as with eval { } - this all isn't about bullet proofing, but - again - I might be wrong.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Mr. Ternary is greater than Mrs. If Else
by PerlPhi (Sexton) on May 19, 2007 at 19:40 UTC |