in reply to eval do {} -- magical variable assignment?
do BLOCK just returns the last statement calculated inside BLOCK, and eval happily connects the evaluated code to the current scope. In contrast, do FILE and require "bequeath an unrelated lexical scope" on the included code according to perlfaq8. So, changing your code slightly
#!/usr/bin/perl use strict; use Data::Dumper; my $file = q{alpha.txt}; my $class; #my $fh; #eval do { # open $fh, "<", $file or die "Unable to open: $!"; # local $/; # <$fh> #}; #die $@ if $@; #close $fh or die "Unable to close: $!"; do $file; print Dumper $class;
results in
$VAR1 = undef;
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: eval do {} -- magical variable assignment?
by aufflick (Deacon) on Jan 02, 2007 at 07:20 UTC |