Other monks have mentioned this, but not in these words: map, grep, and for/foreach arrange for $_ to be an alias to each element of the list in turn. In a map block, $_ is not its own variable and modifying $_ will reach back into the original list. In some cases, $_ can even be aliased to some value slot that is read-only, and attempting to modify $_ will fail; for this reason, subs using $_ should localize *_, which replaces the entire glob and "shadows" any aliases that have been established in outer contexts.
There are several reasons to avoid eval STRING that do not affect eval BLOCK. An obvious problem is that eval STRING parses Perl code from a string. If that string is untrusted remote user input and not very, very, very strictly checked, you have a remote code execution vulnerability. There is also a performance issue, in that eval STRING must invoke perl's parser each time it is reached at runtime, while the BLOCK in eval BLOCK is compiled along with the rest of the program. This also leads to one of the reasons eval STRING can be needed: because the STRING is not compiled until runtime, eval STRING can also trap compilation errors in STRING, while a compilation error in the BLOCK in eval BLOCK is fatal before execution starts.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|