to eval or not to eval?

M

Marc Girod

Hello,

I am trying to eval metacode in a context, and cannot hide the
context.

-8<-------
#!/usr/bin/perl -w

use strict;
my $fubar = q(my $foo = 'bar';);

print eval "$fubar\n";
while (<DATA>) {
print eval "${fubar}qq($_)";
}
print "End\n";
__DATA__
Hello ${foo}!
-8<-------

This gives me:

~> ./tmp/evtst
barHello bar!
End

The first 'bar' there is what annoys me... Go away!
But why is it there?
Yes: it is returned by the assignment to/initialization of $foo...
Why is it part of the return of 'eval'?

Thanks
Marc
 
M

Marc Girod

    the value returned is the value of the last expression evaluated

That's what I thought.
So, what I miss is what is 'last expression evaluated' in: 1;2;
I expected it would be: 2

~> perl -le 'print eval "1;2;"'
2

Why does eval return the result of the *first* expression as well?
This is (still) my question.
Thanks,
Marc
 
M

Marc Girod

Oops... What does this do there?

I thought I had removed that line!
Thanks for pointing it.
Sorry.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top