What am I doing wrong here? I get partially correct information from caller(), but sometimes the filenames seem to be off by one. Background: sub UsageLogger() does a call trace, and sends it to a central server via UDP for tracking local API and script usage. Code in UsageLogger routine looks like:
(undef, $function_basefile, $function_line, $function) = caller(1); (undef, $caller_basefile, $caller_line, $caller) = caller(2);
Sometimes I get the correct info, where the function matches up with function_basefile. But other times, it doesn't seem to match. The function is correct, but the filename is from the caller's caller. The reason for 1,2 is that the call trace looks like:
main -> sub1 -> sub2 -> UsageLogger
For that example, I want to see sub2 as the function, and sub1 as the caller, with the appropriate filenames. Here's an example:
Mon Mar 7 07:09:12 2005 syscron.cc.umr.edu/syscron.cc.umr.edu unixdb: + script = /afs/umr.edu/software/unixdb/bin/load-email-usage-userid.pl + function = UMR::SysProg::ADSObject::new function_file = /afs/umr +.edu/software/umrperl/libs/UMR/SysProg/Exchange.pm function_line += 43 caller = UMR::SysProg::Exchange::new caller_file = /afs/ +umr.edu/software/unixdb/bin/load-email-usage-userid.pl caller_l +ine = 8 cwd = /afs/umr.edu/software/unixdb
ADSObject::new should have been from ADSObject.pm, not Exchange.pm. Exchange::new should have been from Exchange.pm. I saw the note in caller's documentation about losing call frames due to optimization for N > 1, but that doesn't seem to apply here, and I would expect to lose the subroutine call as well, not just the filename.

In reply to Partially wrong info from caller() by nneul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.