考虑一下:
cat > mytestfile.txt <<'EOF'
"'iceberg'"
"'ice cliff'"
"'ice field'"
"'inlet'"
"'island'"
"'islet'"
"'isthmus'"
EOF
perl -dpi -e 's/ice/dice/' mytestfile.txt
当调试器运行时,我尝试添加一个操作来打印$_
,但是:
$ perl -dpi -e 's/ice/dice/' mytestfile.txt
Loading DB routines from perl5db.pl version 1.39_10
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
DB<1> n
main::(-e:1): s/ice/dice/
DB<1> n
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
DB<1> print $_
DB<2> n
main::(-e:1): s/ice/dice/
DB<2> print $_
DB<3> n
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
DB<3> p $_
"'ddiceberg'"
DB<4> print "$_"
...
DB<1> a 0 print "$_";
DB<2> L
DB<3> L a
DB<4> n
...
DB<6> a 1 print "$_"
DB<7> L a
-e:
1: s/ice/dice/
action: print "$_"
DB<8> n
main::(-e:1): s/ice/dice/
DB<8> n
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
DB<8> n
main::(-e:1): s/ice/dice/
DB<8> n
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
DB<8> n
...
DB<8> a 1 p $_
DB<9> L a
-e:
1: s/ice/dice/
action: p $_
DB<10> n
main::(-e:1): s/ice/dice/
Can't locate object method "p" via package " "'ice cliff'"
" (perhaps you forgot to load " "'ice cliff'"
"?) at (eval 13)[/usr/share/perl/5.18/perl5db.pl:732] line 1, <> line 3.
DB<10> n
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
Can't locate object method "p" via package " "'dice cliff'"
" (perhaps you forgot to load " "'dice cliff'"
"?) at (eval 14)[/usr/share/perl/5.18/perl5db.pl:732] line 1, <> line 3.
......有问题:
print $_
,我会得到一个空字符串 - 如果我p $_
,我会得到变量的实际打印输出print $_
用作操作,则看起来不一样,因为如上所述它返回空字符串;但p $_
即使以交互模式打印,也会在用作动作时引发错误。那么我怎样才能将每个循环中的“美元下划线”$_
打印为调试后的-pie
脚本的动作?
答案 0 :(得分:1)
通过How to run `x` command within a < action in the perl debugger?获取,它是{ p $_
:
DB<1> { p $_
DB<2> n
main::(-e:1): s/ice/dice/
auto(-1) DB<2> p $_
"'iceberg'"
DB<3> n
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
auto(-1) DB<3> p $_
"'diceberg'"
DB<4> n
main::(-e:1): s/ice/dice/
auto(-1) DB<4> p $_
"'ice cliff'"
DB<5> n
main::(-e:0): BEGIN { require 'perl5db.pl' };LINE: while (<>) {
auto(-1) DB<5> p $_
"'dice cliff'"