简体   繁体   English

如何在Perl调试器中进行换行以输入原始多行文本(EOT)?

[英]how to do line continuation in perl debugger for entering raw multi-line text (EOT)?

I am learning Perl. 我正在学习Perl。 I am trying in the debugger to define a variable, which is HERE-DOCUMENT. 我正在调试器中尝试定义一个变量,即HERE-DOCUMENT。 I do not know how to enter the same code as in the perl script, but to do it in the debugger. 我不知道如何在perl脚本中输入相同的代码,但是要在调试器中输入。 Due to new lines present inside the EOT, this makes it hard to do in the interactive debugger. 由于EOT中有新行,因此在交互式调试器中很难做到。

Here is a small example. 这是一个小例子。 I have this script: 我有这个脚本:

>cat ex1.perl 
#!/usr/bin/perl -w
my $s =<<'EOT';
this is first line
this is the second line
EOT

print $s

Now I run it and gives expected output: 现在,我运行它并给出预期的输出:

>perl ex1.perl
this is first line
this is the second line

Now I want to do the same in debugger. 现在我想在调试器中做同样的事情。 I tried this: 我尝试了这个:

>perl -de0
Loading DB routines from perl5db.pl version 1.39_10
  DB<1> my $s =<<'EOT';\
  cont: this is first line\
  cont: this is second line\
  cont: EOT
Can't find string terminator "EOT" anywhere before EOF at (eval 6)
[/usr/share/perl/5.18/perl5db.pl:732] line 2.
 at (eval 6)[/usr/share/perl/5.18/perl5db.pl:732] line 2.
    eval 'no strict; ($@, $!, $^E, $,, $/, $\\, $^W) = @DB::saved;package 
    main; $^D = $^D | $DB::db_stop;
my $s =<<\'EOT\';
this is first line
this is second line
EOT;
' called at /usr/share/perl/5.18/perl5db.pl line 732
    DB::eval called at /usr/share/perl/5.18/perl5db.pl line 3090
    DB::DB called at -e line 1

I do not think using \\ is correct even, but if I do not use \\ debugger will also complain. 我认为即使使用\\也不正确,但是如果我不使用\\ debugger也会抱怨。 So I am not sure how to enter the EOT text in the debugger. 所以我不确定如何在调试器中输入EOT文本。

Is there a way to type in the same thing in the perl script, but using the debugger? 有没有办法在perl脚本中键入相同的内容,但是要使用调试器? I wanted to test things more easily in the debugger on EOT. 我想在EOT的调试器中更轻松地测试事物。

I am using 我在用

>perl --version

This is perl 5, version 18, subversion 2 (v5.18.2) built for 
x86_64-linux-gnu-thread-multi

Notice the ; 注意; after EOT in the command that's actually run? 在实际运行的命令中EOT之后? That's causing the problem. 这就是问题所在。 We'll need to fool the debugger. 我们需要欺骗调试器。

  DB<1> $s = <<'EOT';\

  cont: abc\

  cont: def\

  cont: EOT\

  cont: 1


  DB<2> x $s
0  'abc
def
'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM