Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

All of this is on 5.8.3, ActiveState build 809

Yes, the bug is that an error within eval should not affect other evals. I'm not sure where the problem lies, because the following code still works as expected and raises no error, no matter whether $string is a global or a lexical variable:

use strict; use Test::More tests => 12; sub second_eval_unaffected($) { my ($code) = @_; eval $code; diag $@ if $@; my $string = ''; ok eval(q($string="new eval done";)), "Eval after >>$code<< still +works"; is $@, '', "... and raises no error either."; is $string, 'new eval done', "... and sets the variable correctly" +; }; second_eval_unaffected 'my $var_without_accent;'; second_eval_unaffected 'my $var_with = "é_accent";'; second_eval_unaffected 'my statement_with_error;'; second_eval_unaffected 'my $var_with_é_accent";';

This program exhibits the problem as a self-contained Test::More program. The first sequence of steps leads to a failure, while the second run succeeds. This should not happen, but I don't know why :)

use strict; use Test::More tests => 10; sub gauntlet { my $code1=shift; my $string; my $expected = "new eval done"; my $code2='$string="new eval done";'; ok eval($code2), "Good code evals correctly"; is $@, '', "... and raises no error on its own."; diag "Eval trial code\n"; diag $code1; eval $code1; diag '$@ is ', $@; undef $string; diag "Eval good code ($code2)\n"; ok eval $code2; is $@, '', "No error raised"; is $string, $expected; }; gauntlet('my $var_with_é_accent;'); gauntlet('my $var_without_accent;');

In reply to Re^2: Bug : eval and accent by Corion
in thread Bug : eval and accent by sylvanus_monachus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found