in reply to Coderef to String conversion?

You'll need to use B::Deparse for this; for instance:

use B::Deparse; use Data::Dumper; my $deparse = B::Deparse->new; print $deparse->coderef2text( sub{print 'Yeah'} )

As for Data::Dumper, the newest version (the one that came with 5.8.0; if you don't have it, get it from the CPAN) has an option called Deparse; turn it on, and it will use B::Deparse to stringify coderefs for you:

my $test = { test => 1, code => sub { print 'Yeah'; }, aref => [ qw(1 2 3 4 5) ], }; $Data::Dumper::Deparse = 1; print Dumper($test);

Replies are listed 'Best First'.
Re: Re: Coderef to String conversion?
by joe++ (Friar) on Mar 08, 2003 at 09:43 UTC
    jryan,

    Cool, B::Deparse just does the trick!
    I'm using 5.6.1 right now, and I don't want to limit my script to 5.8x for the time being...

    Thanks!

    --
    Cheers, Joe

      Keep in mind that B::Deparse isn't guaranteed to produce correct results and that it won't help you with any bound lexicals if you're using closures. But since you aren't writing Obfuscations your code will probably come out just fine.


      Seeking Green geeks in Minnesota

      You don't need perl 5.8.0, just the version of Data::Dumper that comes with it. You can find it here.