in reply to Is it possible to view a string representaion of a code ref?
Several:
use Data::Dumper; $Data::Dumper::Deparse = 1; my $sub; { my $x = "foo"; $sub = sub { my $filename = shift; return "/tmp/$x/" . $filename; }; } print Dumper($sub); __END__ $VAR1 = sub { my $filename = shift @_; return "/tmp/$x/" . $filename; };
use Data::Dump::Streamer; my $sub; { my $x = "foo"; $sub = sub { my $filename = shift; return "/tmp/$x/" . $filename; }; } print Dump($sub); __END__ my ($x); $x = 'foo'; $CODE1 = sub { my $filename = shift @_; return "/tmp/$x/" . $filename; };
use B::Deparse; my $deparse = B::Deparse->new; my $sub; { my $x = "foo"; $sub = sub { my $filename = shift; return "/tmp/$x/" . $filename; }; } print $deparse->coderef2text($sub),"\n"; __END__ { my $filename = shift @_; return "/tmp/$x/" . $filename; }
update: added a block scope, from which you can see that out of those only Data::Dump::Streamer provides the sub's context.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is it possible to view a string representaion of a code ref?
by targetsmart (Curate) on May 14, 2009 at 05:58 UTC | |
by ysth (Canon) on May 14, 2009 at 06:40 UTC | |
by targetsmart (Curate) on May 14, 2009 at 11:35 UTC | |
by Anonymous Monk on May 14, 2009 at 11:59 UTC | |
by targetsmart (Curate) on May 14, 2009 at 12:43 UTC | |
| |
|
Re^2: Is it possible to view a string representaion of a code ref?
by astroboy (Chaplain) on May 14, 2009 at 00:22 UTC |