-
Notifications
You must be signed in to change notification settings - Fork 577
caller() reports $line numbers inconsistantly #4125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From [email protected]When a function call spans several lines, caller sometimes reports the my $tag = "#CALLER";
sub tagCall
{
my ($package, $file, $line) = caller;
open CALLER, "$file";
my @lines = <CALLER>;
$lines[$line-1] =~ s/\s?($tag)?(\s*)$/ $tag$2/;
open CALLER, ">$file";
print CALLER @lines;
}
tagCall #CALLER
"abc",
"123",
"foo";
tagCall
"abc",
sub {},
"foo"; #CALLER It might be that no one else cares about this, but it matters to
This offer is good until September 1st 2001. Payment by PayPal or Perl Info
|
From [email protected]A much easier example of the code: #!/usr/bin/perl -l
use strict;
use warnings;
sub tagCall {
my ($package, $file, $line) = caller;
print "LINE = $line";
}
tagCall
"abc";
tagCall
sub {};
__END__
tagCall in the source code is on line 11 and on line 14. Running the script:
|
From @HugmeirHah, I guess that, ten years ago, no one liked money. This is still |
@Hugmeir - Status changed from 'open' to 'stalled' |
Also present on 5.30 |
On Fri, 31 Jan 2020 at 08:55, Todd Rinaldo ***@***.***> wrote:
Also present on 5.30
This should probably be consolidated into a single ticket on line number
issues. There are many variants, but the general theme is that for
efficiency reasons we don't store line and file data for every opcode, and
instead only do so for COP's and sometimes this means Perl gets quite a bit
muddled about what line something happened on.
Yves
$ cat muddle.pl
```perl
use strict;
use warnings;
use Carp;
sub t1 {
Carp::confess("t1") if $ARGV[0] == 1;
}
sub t2 {
Carp::confess("t2") if $ARGV[0] == 2;
}
sub t3 {
Carp::confess("t3") if $ARGV[0] == 3;
}
if (t1) {
} elsif (t2) {
} elsif (t3) {
}
$ perl muddle.pl 1
t1 at muddle.pl line 6.
main::t1() called at muddle.pl line 16
$ perl muddle.pl 2
t2 at muddle.pl line 9.
main::t2() called at muddle.pl line 16
$ perl muddle.pl 3
t3 at muddle.pl line 12.
main::t3() called at muddle.pl line 16
```
Notice all three case say their function was called on line 16, but they
were actually called at lines 16, 18, and 20 respectively.
Yves
|
Migrated from rt.perl.org#7165 (status was 'stalled')
Searchable as RT7165$
The text was updated successfully, but these errors were encountered: