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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |