in reply to eval that doesn't exec?
It also works if you need to eval a string, then you can do like this:# store a reference to a sub my $coderef = sub { print shift || "Foo"; print "\n"; }; # execute code, with or without arguments $coderef->(); $coderef->('Bar'); $coderef->();
my $code =<<'CODE'; print shift || "Foo"; print "\n"; CODE my $coderef = eval"sub{$code}";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: eval that doesn't exec?
by dsheroh (Monsignor) on May 11, 2002 at 17:43 UTC | |
by Dog and Pony (Priest) on May 11, 2002 at 17:47 UTC | |
by zjunior (Beadle) on May 11, 2002 at 18:27 UTC | |
by merlyn (Sage) on May 11, 2002 at 18:51 UTC |