in reply to Re: Re: Re: Re: Good way of getting subroutine name from ref?
in thread Good way of getting subroutine name from ref?

Ok, so if the problem is context, solve that problem: scalar eval { ... } neatly describes the issue without the || undef which I'm nitpicking because I don't like the style.

Replies are listed 'Best First'.
Re^5: Good way of handling eval failures and deparsing formats
by ysth (Canon) on Dec 07, 2003 at 22:09 UTC
    Fair enough. The scalar() version is certainly more efficient, but I think the || undef is more descriptive.

    Just to keep this post from having zero value, here's another case where I used B without eval. The problem was to show what a format (set via a complex eval STRING) was getting set to. Original version only allowed deparse_format(*WHATEVER{FORMAT}) but *FOO{FORMAT} isn't supported before perl-5.7.0.

    sub deparse_format { use B::Deparse; # translate arg (or reference to it) into a B::* object my $Bobj = B::svref_2object(ref $_[0] ? $_[0] : \$_[0]); # if passed a glob or globref, get the format $Bobj = B::GV::FORM($Bobj) if ref $Bobj eq 'B::GV'; if (ref $Bobj ne 'B::FM') { require Carp; Carp::croak "deparse_format: expected a glob, globref, or form +at ref"; } my $deparser = B::Deparse::->new(); return $deparser->indent($deparser->deparse_format($Bobj)); }