in reply to Perl's __LINE__ off by 2
> $spinner->count('benchLoop', __FILE__, __LINE__);
can be reduced to $spinner->count('benchLoop') if you check caller to retrieve file and line inside the count() method.
Choroba's tip to use # line 123 directive is legit, see Plain-Old-Comments
So try to debug where the "strangeness" starts to happen in your file.
:~$ perl $\="\n"; print __LINE__; # line 120 print __LINE__; __END__ 2 120
> Any idea why __LINE__ would be consistently off by 2?
Like Corion said, any module injecting code, like by using source filters could silently add additional lines.
Regarding your newline theory, try to end your file with __DATA__ and put this into your code right before calling ->count to check what the engine actually sees as different lines before compiling.
seek DATA,0,0; my @lines = <DATA>; say Dumper \@lines;
for instance
use v5.12; use warnings; use Data::Dumper; say __LINE__; say __LINE__; say __LINE__; seek DATA,0,0; my @lines = <DATA>; say Dumper \@lines; __DATA__
4 5 6 $VAR1 = [ 'use v5.12; ', 'use warnings; ', 'use Data::Dumper; ', 'say __LINE__; ', 'say __LINE__; ', 'say __LINE__; ', ' ', ' ', 'seek DATA,0,0; ', 'my @lines = <DATA>; ', 'say Dumper \\@lines; ', ' ', '__DATA__ ' ];
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl's __LINE__ off by 2
by ysth (Canon) on Aug 26, 2025 at 04:05 UTC | |
by LanX (Saint) on Aug 26, 2025 at 10:20 UTC | |
by ysth (Canon) on Aug 26, 2025 at 16:22 UTC | |
by LanX (Saint) on Aug 26, 2025 at 16:43 UTC | |
Re^2: Perl's __LINE__ off by 2 ($PERLDB)
by LanX (Saint) on Aug 26, 2025 at 16:10 UTC |