It is the caller subroutine.  I use it for printing start and stop times for 
particular subs. So the print sub references who called him by something like:

#!perl -w

sub a {
    &c;
    $caller = (caller(0))[3];
    $caller =~ s/.*:://;
    print "0 I am $caller\n";
 };

sub b {&c};
sub c {
  my $caller = (caller(1))[3];
  $caller =~ s/.*:://;
  print "called by $caller\n";
  $caller = (caller(0))[3];
  $caller =~ s/.*:://;
  print "1 I am $caller\n";
}

a;
b;

chomp(my $res = <STDIN>);
outputs:

called by a
1 I am c
0 I am a
called by b
1 I am c

        A starting point. Only gets you started.

Wags ;)

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Eckart Uhlig
Sent: Friday, December 19, 2003 12:41
To: [EMAIL PROTECTED]
Subject: subroutine name


Hi all,
is there a way to determine the name of the current called subroutine? I
don't want to print out the subroutine's name explicitly, I'm hoping for
a 'magic' variable/ function or something like that, which I can pass to
a plain printout function. In the perlvars manpage I haven't found
anything.


# code snippet begin 
sub anySubfunc1
{
        Print_func_name($magic_var)
        # doing something 
}

sub anySubfunc2
{
        Print_func_name($magic_var)
        # doing something 
}

sub Print_func_name
{
        my ($tmpname)[EMAIL PROTECTED];
        print "\nprocessing sub: $tmpname";
}
# code snippet end 

Thanks in advance.
Eckart 

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to