On Wed, Jun 16, 2010 at 10:32 AM, Tom Metro <[email protected]> wrote:
> I have some code with an anonymous sub that uses __ANON__ to set the sub
> name in logging and error messages (a semi-documented trick) like:
>
> sub {
> local *__ANON__ = "subname"; # name the anon sub
> [...]
>
> warn *__ANON__,": ...\n";
Rather than a semi-documented trick, I'd recommend the clearly
documented Sub::Name module for this. It does the same thing, with
less confusion for the maintenance programmer.
> The problem comes about with the warn call that wants to reference
> __ANON__. If __ANON__ is used by itself, it produces a bareword warning.
> If it is used as a glob (either *__ANON__ or *{__ANON__}), it works, but
> produces output prefixed with "*", which seems to suggest it isn't
> really being interpreted as a glob.
>
> While the real code is going to end up using a Log::Log4perl method
> instead of warn (which internally uses caller()), making this moot, I'm
> curious to know what the correct syntax is here.
I believe you have the right syntax. The * prefix just indicates that
it is being interpreted as some other glob, but if you look at the
output the glob it appears as should be what you were trying to name
it.
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm