in reply to caller() returns wrong line on multi-line function call

Good catch!!!

The problem already happens during compilation, the "wrong" line numbers are stored into the op-tree (see "nextstate")

I ran your code through B::Deparse and B::Concise to be sure

-*- mode: compilation; default-directory: "d:/Users/RolfLangsdorf/pm/" + -*- Compilation started at Thu Sep 14 16:09:01 C:/Perl_64/bin\perl.exe pm/caller_subline.pl Perl v5.016003 Called from line 18; caller() reports line 18 Called from line 23; caller() reports line 24 === B::Deparse -l: { use strict; #line 18 "pm/caller_subline.pl" print_calling_line('18', {'A', 1, 'B', 2, 'C', 3}); #line 24 "pm/caller_subline.pl" print_calling_line('23', do { 'A', 1, 'B', 2, 'C', 3 }); } === B::Concise: main::tst: r <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->r 1 <;> nextstate(main -5 caller_subline.pl:18) v:*,&,x*,x&,x$,$ +->2 d <1> entersub[t3] vKS/TARG,2 ->e - <1> ex-list K ->d 2 <0> pushmark s ->3 3 <$> const[PV "18"] sM ->4 b <@> anonhash sKM*/1 ->c 4 <0> pushmark s ->5 5 <$> const[PV "A"] s/BARE ->6 6 <$> const[IV 1] s ->7 7 <$> const[PV "B"] s/BARE ->8 8 <$> const[IV 2] s ->9 9 <$> const[PV "C"] s/BARE ->a a <$> const[IV 3] s ->b - <1> ex-rv2cv sK/2 ->- c <#> gv[*print_calling_line] s ->d e <;> nextstate(main -4 caller_subline.pl:24) v:*,&,x*,x&,x$,$ +->f q <1> entersub[t6] KS/TARG,2 ->r - <1> ex-list K ->q f <0> pushmark s ->g g <$> const[PV "23"] sM ->h - <1> null lKM*/1 ->p - <@> scope lK ->- - <0> ex-nextstate v ->h o <@> list lK ->p h <0> pushmark s ->i i <$> const[PV "A"] s/BARE ->j j <$> const[IV 1] s ->k k <$> const[PV "B"] s/BARE ->l l <$> const[IV 2] s ->m m <$> const[PV "C"] s/BARE ->n n <$> const[IV 3] s ->o - <1> ex-rv2cv sK/2 ->- p <#> gv[*print_calling_line] s ->q Compilation finished at Thu Sep 14 16:09:01

#!/usr/bin/perl -w use strict; use B::Deparse; use B::Concise; print "Perl v",$],"\n"; sub print_calling_line { my $actual_line = $_[0]; my $caller_line = (caller)[2]; printf "Called from line %2d; caller() reports line %2d\n", $actual_line, $caller_line; } sub tst { print_calling_line( __LINE__, {A => 1, B => 2, C => 3} ); print_calling_line( __LINE__, do { A => 1, B => 2, C => 3 } ); } tst(); print "\n === B::Deparse -l:\n". B::Deparse->new("-l")->coderef2text(\ +&tst); print "\n === B::Concise:\n"; my $walker = B::Concise::compile('tst'); $walker->();

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

added code, rearranged output