At run-time, only the line numbers of statements are available (for efficiency reasons), so it should say the caller is line 5.

$ perl -e' # 1 my %h = ( # 2 a => 1, # 3 b => warn("This is line 4"), # 4 c => 1 # 5 ); # 6 ' # 7 This is line 4 at -e line 2.

That it says the statement starts a line 12 is a bug. As you probably noticed, the problem is related to the nested statement at line 11. Replace the sub { } with a constant and the caller will become line 5.

$ perl -MO=Concise,-exec -e' my %h = ( a => 1, b => 1, c => 1, ); my $x = 1; ' 1 <0> enter 2 <;> nextstate(main 1 -e:2) v:{ <-- Sets the line number to 2. 3 <0> pushmark s 4 <$> const[PV "a"] s/BARE 5 <$> const[IV 1] s 6 <$> const[PV "b"] s/BARE 7 <$> const[IV 1] s 8 <$> const[PV "c"] s/BARE 9 <$> const[IV 1] s a <0> pushmark s b <0> padhv[%h:1,3] lRM*/LVINTRO c <2> aassign[t2] vKS d <;> nextstate(main 2 -e:7) v:{ <-- Sets the line number to 7. e <$> const[IV 1] s f <0> padsv[$x:2,3] sRM*/LVINTRO g <2> sassign vKS/2 h <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e' my %h = ( a => 1, b => sub { }, c => 1, ); my $x = 1; ' 1 <0> enter 2 <;> nextstate(main 2 -e:5) v:{ <-- Sets the line number to 5!?!? 3 <0> pushmark s 4 <$> const[PV "a"] s/BARE 5 <$> const[IV 1] s 6 <$> const[PV "b"] s/BARE 7 <0> pushmark sRM 8 <$> anoncode[CV ] lRM 9 <1> refgen lK/1 a <$> const[PV "c"] s/BARE b <$> const[IV 1] s c <0> pushmark s d <0> padhv[%h:2,4] lRM*/LVINTRO e <2> aassign[t3] vKS f <;> nextstate(main 3 -e:7) v:{ <-- Sets the line number to 7. g <$> const[IV 1] s h <0> padsv[$x:3,4] sRM*/LVINTRO i <2> sassign vKS/2 j <@> leave[1 ref] vKP/REFC -e syntax OK

In reply to Re: CORE::GLOBAL::caller reports strange lines around coderef definitions by ikegami
in thread CORE::GLOBAL::caller reports strange lines around coderef definitions by ed_hoch

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.