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

时间:2015-07-11 00:11:15

标签: perl

我正在学习Perl。我正在尝试在调试器中定义一个变量,这是HERE-DOCUMENT。我不知道如何输入与perl脚本相同的代码,但是要在调试器中执行。由于EOT中存在新行,因此很难在交互式调试器中执行此操作。

这是一个小例子。我有这个脚本:

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

print $s

现在我运行它并给出预期的输出:

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

现在我想在调试器中做同样的事情。我试过这个:

>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

我不认为使用\是正确的,但如果我不使用\,调试器也会抱怨。所以我不确定如何在调试器中输入EOT文本。

有没有办法在perl脚本中键入相同的内容,但是使用调试器?我想在EOT上的调试器中更容易地测试一些东西。

我正在使用

>perl --version

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

1 个答案:

答案 0 :(得分:2)

请注意命令中;之后的EOT实际运行?导致问题的原因。我们需要欺骗调试器。

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

  cont: abc\

  cont: def\

  cont: EOT\

  cont: 1


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