The documentation about the eval function mentions nothing of the sort. Clearly having compiler warnings for every instance of eval seems ridiculous, but I feel that something about this needs to be in the main documentation about the eval function.
Patches welcome.

Your example is actually working with two completely different scopes. Consider this:

use temp1; use warnings; use strict; temp1::init(); use temp1; use warnings; use strict; temp1::init(); print "Calling work1: " . temp1::work1( '$var = 3' ) . "\n"; print "Calling work2: " . temp1::work2( '$var++' ) . "\n"; print "Calling work3: " . temp1::work3( '$var++' ) . "\n"; print "Work3 again: " . temp1::work3( '++$var' ) . "\n"; print "Calling work4: " . temp1::work4( '$var++' ) . "\n";
package temp1; use strict; use warnings; my $var; sub init { $var = 101 } sub work1 { return eval shift; } sub work2 { my $foo = shift; return eval $foo; $var } sub work3 { return eval $_[0]; } sub work4 { eval $var; } 1;
The output is:
Calling work1: 3 Calling work2: 101 Calling work3: 3 Work3 again: 5 Calling work4: 102

In reply to Re^2: quantum behavior in perl? by mr_mischief
in thread quantum behavior in perl? by b4swine

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.