Why are the error messages different?

I have two programs:

#line 1 "DB::eval"
234asd

perl < tmp.pl
Bareword found where operator expected at DB::eval line 1, near "234asd"
    (Missing operator before asd?)
syntax error at DB::eval line 2, near "234asd
"
Execution of - aborted due to compilation errors.

      

and the second one:

$str =  <<CODE;
#line 1 "DB::eval"
234asd
CODE
eval $str;
print $@;

perl < tmp.pl
Bareword found where operator expected at DB::eval line 1, near "#line 1 "DB::eval"
234asd"
    (Missing operator before asd?)
syntax error at DB::eval line 2, near "#line 1 "DB::eval"
234asd

"

      

Why, in the second case, I got additional text in the error message #line 1 "DB::eval"

:? I don't expect this.

Also in the second case I am not expecting an extra newline. I am waiting:

234asd
"

      

Instead:

234asd

"

      

+3


source to share


1 answer


I would not call this a bug, just behavior dependent.

The second variant of heredoc includes more context. No one guarantees that heredoc'd evals behave the same as direct scripts.



p5p agreed with me, Zefram didn't call it a bug and SawyerX rejected it.

+1


source







All Articles