andreas1234567 has asked for the wisdom of the Perl Monks concerning the following question:
Unfortunately, it's not possible to dump a subroutine reference using ''Data::Dumper'' or other tools. Perl doesn't (yet) have a way of turning a subroutine back into code. If we do pass a subroutine reference to Data::Dumper, it will instead print a place holder:This is easily confirmed on the command line:use Data::Dumper; print Dumper $sub_ref; # prints $VAR1 = sub { "DUMMY" };
Have this evolved since March 2005? Are there ways to turn a reference to a subroutine back into code?$ perl use strict; use warnings; use Data::Dumper; my $coderef = sub { print "hello world\n"; }; print Dumper($coderef); __END__ $VAR1 = sub { "DUMMY" };
Update Fri Apr 18 09:50:54 CEST 2008: Thank you Monk with no name:
$ perl use strict; use warnings; use Data::Dumper; my $coderef = sub { print "hello world\n"; }; $Data::Dumper::Deparse=1; print Dumper($coderef); __END__ $VAR1 = sub { use warnings; use strict 'refs'; print "hello world\n"; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Turning a reference to a subroutine back into code
by citromatik (Curate) on Apr 18, 2008 at 07:52 UTC | |
by dragonchild (Archbishop) on Apr 18, 2008 at 14:12 UTC | |
|
Re: Turning a reference to a subroutine back into code
by Anonymous Monk on Apr 18, 2008 at 07:31 UTC | |
|
Re: Turning a reference to a subroutine back into code
by FunkyMonk (Bishop) on Apr 18, 2008 at 08:24 UTC | |
by citromatik (Curate) on Apr 18, 2008 at 08:44 UTC |