我不相信调试器中内置了任何东西可以做到这一点,但我滚动了我自己的绑定标量类并在“ScalarSnoop::STORE”子例程上设置了一个断点。
这是课程:
package ScalarSnoop;
use strict;
use base qw(Tie::Scalar);
sub TIESCALAR {
my $class = shift;
my $value = shift;
return bless \$value, $class;
}
sub FETCH {
my $self = shift;
return $$self;
}
sub STORE {
my $self = shift;
my $newvalue = shift;
$$self = $newvalue;
}
1;
这是一个使用它的脚本:
#!/usr/bin/env perl
use v5.14.0;
use strict;
use warnings;
use lib qw(.);
use ScalarSnoop;
my ($first, $second, $third);
tie $second, 'ScalarSnoop';
$first = 'hey';
$second = 'there';
$third = 'dude';
# Changing the iterator variable changes the original since
# it is an alias
foreach my $variable (($first, $second, $third)) {
$variable = "like, ${variable}";
say "$variable";
}
启动调试器并设置断点b postpone ScalarSnoop::STORE
。继续运行,当有人在您的标量中存储值时,调试器将停止。然后你可以转储堆栈跟踪并查看它是谁。