At what point of processing the script does an eval function get parsed ? Is it not compile time ? Or is it run time ?
There are two types of eval which behave quite differently:  eval STRING and eval BLOCK. If eval is passed a string parameter, it is parsed and compiled at runtime; if it is passed an unquoted block of code, it is parsed and compiled at compile-time.
Also, why does
if(require "module/that/does/not/exist") { print "loaded module ok\n"; }else{ print "could not load module $@\n"; }
not work ?
require dies if it can't find the file it's looking for, rather than simply returning an error. require is a sort of assertion, and if it fails it's considered too severe to keep on running.
if I do
eval { require "module/that/does/not/exist"; }
nothing happens ? Do I have to check $@ after eval ? Do i have to check if $@ is defined after every eval call ?
Yes, you have to check $@ after every eval to see if anything in the eval failed.
Also, why does this small print statement not generate error ?
print petrol "hello there !";
If you run perl without warnings and strict, undeclared variables simply spring into existence. In this case, petrol is created the first time you use it. It doesn't go anywhere, so output to it is simply discarded. If you add:
use warnings; use strict;
to the top of your Perl code, you'll get an error if you try to do this. I recommend starting off all of your scripts that way.

In reply to Re: Question about eval by sgifford
in thread Question about eval by tiny_tim

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.