in reply to eval do {} -- magical variable assignment?

The "do" has nothing to do with it. It's all magic of the eval $string construct.

Try this, and you'll see the same effect:

my $string = '$data = "foo"'; { my $data; eval $string; print $data; }

In both perls I tested this in (5.6.1 and 5.8.3), this prints "foo".

The do BLOCK only serves to locally undef $/, and thus, read the entire file into the string. The result of it, is just a string, that then gets evalled.

You are right that it's a remarkable difference with require and use, that are indeed somewhat similar, as is do STRING; but that's a different kind of do, unrelated to this here, which is do BLOCK.

Replies are listed 'Best First'.
Re^2: eval do {} -- magical variable assignment?
by jkeenan1 (Deacon) on Dec 30, 2006 at 03:00 UTC
    It's all magic of the eval $string construct.

    ... which I didn't pick up on because I rarely use either eval $string or do.

    Thanks, monks!

    Jim Keenan