in reply to Turning a reference to a subroutine back into code

Data::Dump::Streamer can do that. Here is the different outputs you can get with Data::Dumper and Data::Dump::Streamer

use strict; use warnings; use Data::Dumper; use Data::Dump::Streamer; sub makeGreeting { my $str = "Hello "; return sub { my ($name) = @_; print "$str $name\n"; } } my $greet = makeGreeting(); $greet->("Mike"); print "From Data::Dumper\n",Dumper $greet,"\n\n"; print "From Data::Dump::Streamer\n",Dump $greet;

This code outputs:

Hello Mike From Data::Dumper $VAR1 = sub { "DUMMY" }; From Data::Dump::Streamer my ($str); $str = 'Hello '; $CODE1 = sub { use warnings; use strict 'refs'; my($name) = @_; print "$str $name\n"; };

Hope this helps

citromatik

Replies are listed 'Best First'.
Re^2: Turning a reference to a subroutine back into code
by dragonchild (Archbishop) on Apr 18, 2008 at 14:12 UTC
    I do this in Sub::Compose.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?