Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

It seems that I haven't understood properly the perldocs of the caller function. My understanding was that with caller(1), I walk up one frame (i.e. get the information about who is calling me), with caller(2) I walk up 2 frames, etc.

But now look at the following example program. _format_caller is called twice; the first time it is supposed to print what is returned by caller(1), the second time caller(2).

use strict; use warnings; sub _format_caller { my @x=caller($_[0]); print "elements:",scalar(@x),"\n"; print(join(',',@x),"\n"); } sub f { my $level=$_[0]; print "test caller $level\n"; _format_caller($level); } f(1); f(2);
The actual printout looks like this:
> Use of uninitialized value in join or string at U:\develsv\ARTS\playgr +ound\callertest.pl line 7. Use of uninitialized value in join or string at U:\develsv\ARTS\playgr +ound\callertest.pl line 7. Use of uninitialized value in join or string at U:\develsv\ARTS\playgr +ound\callertest.pl line 7. test caller 1 elements:10 main,U:\develsv\ARTS\playground\callertest.pl,16,main::f,1,,,,2,UUUUUU +UUUUU test caller 2 elements:0
Well, the uninitialized warnings are because some of the elements returned by caller are undef. But why don't I get anything back in the case of caller(2)?

-- 
Ronald Fischer <ynnor@mm.st>

In reply to caller() mystery by rovf

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (7)
    As of 2020-05-29 14:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      If programming languages were movie genres, Perl would be:















      Results (169 votes). Check out past polls.

      Notices?