我想知道是否有一种方法可以在Perl调试器配置文件.perldb
中为转储表达式的命令x
定义别名。
以下所有可想象的别名定义都无效:
cat .perldb
$DB::alias{ 'x0' } = "x '%states'"; # Does not work
$DB::alias{ 'x1' } = 'x %config'; # Does not work
$DB::alias{ 'x2' } = '"x %config"'; # Does not work
$DB::alias{ 'x3' } = 'x "%config, $foo"'; # Does not work
$DB::alias{ 'x4' } = 'x "@L"'; # Does not work
$DB::alias{ 'x5' } = 'x %config, $foo'; # Does not work
$DB::alias{ 'x6' } = '"x %config, $foo"'; # Does not work
$DB::alias{ 'xc' } = 'x %config'; # Does not work
$DB::alias{ 'pFoo1' } = 'print("foo=$var1\n")'; # Works
$DB::alias{ 'pFoo2' } = 'print("$var2\n")'; # Works
$DB::alias{ 'p1' } = 'print "\$_ = $_"'; # Works
$DB::alias{ 'code' } = 's/^.*$/l 1+99999/'; # Works
使用'perl -d script.pl'启动调试器并使用=
显示别名后,我得到:
code s/^.*$/l 1+99999/
p1 print "\$_ = $_"
pFoo1 print("foo=$var1\n")
pFoo2 print("$var2\n")
x0 x '%states'
x1 x %config
x2 "x %config"
x3 x "%config, $foo"
x4 x "@L"
x5 x %config, $foo
x6 "x %config, $foo"
xc x %config
任何想法,如果.perldb
中的别名定义需要特殊的语法还是不起作用?
答案 0 :(得分:3)
未记录,但the contents of the %alias
hash are strings that are used as the right-hand side of a $cmd =~ ...
expression。也就是说,要按预期工作,别名必须是s///
命令。
尝试类似
$DB::alias{ 'x1' } = 's/^.*/x %config/';