[Chicago-talk] Finding out where a sub is called from

Andy_Bach at wiwb.uscourts.gov Andy_Bach at wiwb.uscourts.gov
Mon Feb 16 09:14:24 PST 2009

I've used:
  my $ident = 'web ';
  $ident .= "$DBNAME " if $DBNAME;
  for my $level ( 0 .. 5 ) {
    #my ($package, $filename, $line) = caller($level);
    my ($package, $filename, $line, $subroutine, $hasargs,
        $wantarray, $evaltext, $is_require, $hints, $bitmask)
        = caller($level);
    last unless $filename and $filename =~ /\w/;
    $subroutine = $evaltext if $subroutine eq "(eval)";
    $package = ($package eq "main" ? "" : $package . "::");
    $filename =~ s|\.\./|/|g;
    $filename =~ s|//|/|g;
    $ident .= "called from $package" . "$filename($subroutine line: $line) 
  }    # for level

This is to create a preamble to an error msg for use w/ syslog but the 
idea is to walk back the caller stack a ways in case A called B called C 
called D (who's outputting the mgs).

Andy Bach
Systems Mangler
Internet: andy_bach at wiwb.uscourts.gov
Voice: (608) 261-5738; Cell: (608) 658-1890

 A host is a host, from coast to coast
and everyone talks to a host that's close
unless of course, the host that's close
is busy, hung or dead. -- DCP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20090216/9b4b4ff2/attachment.html>

More information about the Chicago-talk mailing list