#!perl -l use strict; use warnings; sub routine1 { print "Who am I?"; } sub routine2 { print "Where am I?"; } my %all_subs = map { (\&{$main::{$_}} => $_) } grep { defined &{$main::{$_}} } keys %{main::} ; my $some_sub = \&routine1; if ($all_subs{$some_sub}) { print "Found $all_subs{$some_sub}" } else { print "Sub not found"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding the name of a code ref
by cazz (Pilgrim) on Apr 05, 2005 at 20:51 UTC | |
|
Re: Finding the name of a code ref
by merlyn (Sage) on Apr 05, 2005 at 20:47 UTC | |
|
Re: Finding the name of a code ref
by ysth (Canon) on Apr 06, 2005 at 07:20 UTC |