SPUG: do vs. eval with Data::Dumper

John Labovitz johnl at meer.net
Wed Jan 26 11:43:59 CST 2000


> It looks like "do" is executing the code in its own scope, but eval is
> using the surrounding scope.

that almost makes sense.  back in the old days (before i used perl,
i must admit), you called subroutines using `do sub'.  later, you
could use `&sub'; now you can use `sub()'.

looking at that, it would make sense that `do $code', where $code is
Data::Dumper output, is like calling a subroutine that is implemented
with the code in $code.

whereas `eval' is simply evaluating that code, inline with your
current location (scope).

btw, i've had better luck with this:

    my $code = Data::Dumper([$data]);
    my $result = do $code;

it only helps your problems with globals in that you don't *have* any
globals. ;)

> And why doesn't Data::Dumper export Dump() in the first place? 8-}

because it exports Dumper() instead. ;)

john

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list