Reputation: 8042
In my perl script I am reading user input via following construction:
# READ INPUT IN TO THE ARRAY, LINE BY LINE AND REMOVE SLASHES /, BLANK CHARACTERS, EMPTY LINES, AND NEWLINES
while (<>) {
$_ =~ s/\\//g; # Remove slash /
$_ =~ s/^\s+|\s+$//g; # Remove heading and trailing white spaces
$_ =~ s/^\s*$//g; # Remove white spaces
$_ =~ s/\r|\n//g; # Remove CR and NL
if ($_ !~ /^\s*$/ &&
$_ !~ /:/ &&
($_ =~ /^[^=#]+=[^=#]+$/ || $_ =~ /^#+$/)){
push @raw_admin_input, split "\n", $_;
}
}
So when I run the script I am able to paste (or type) multi-line line (enter separated) string then press enter again and hit ctrl+d
to signalize the end of user input and it works.
Now I need to debug this script
main::(stdin.pl:177): while (<>) { # READ INPUT IN TO THE ARRAY, LINE BY LINE AND REMOVE SLASHES /, BLANK CHARACTERS, EMPTY LINES, AND NEWLINES
DB<4> s
input1
main::(skript12.pl:179): $_ =~ s/\\//g; # Remove slash /
DB<4> input2
DB<5> input3
DB<6> #############
DB<7> sdasda=asdasd
Can't modify constant item in scalar assignment at (eval 13)[/usr/share/perl5/core_perl/perl5db.pl:732] line 2, at EOF
The problem is that perl debugger recognizes this as a commands for debugger and not as a input from STDIN. I am pretty sure that this worked before and I am not aware that I've changed mentioned STDIN reading process. I have also found that there are several ways of faking STDIN, but unfortunately I am a little bit confused with their syntax and do not know how to use them.
Upvotes: 1
Views: 767
Reputation: 4104
The Perl Debugger will take input from the Terminal. If the program you are debugging is reading STDIN and your program had inherited the Terminal as it's STDIN, then you will be in the situation you are in.
You have three choices that allow you to keep reading from <>
:
redirect STDIN from another source: perl -d myprog.pl < mystdin.txt
or program_that_generates_usefull_input | perl -d myprog.pl
Take advantage of the fact that <>
reads from STDIN or files named in ARGV: perl -d myprog.pl myargv1.txt myargv2.txt
Pay very close attention to which program is asking for input.
In your example above, you s
tep through the while
line requesting input; You enter the text input1
into the program being debugged; then while the debugger is asking what to do about the 1st substitution line, you ignore the debugger hoping that the paused program might currently be accepting more text.
Upvotes: 4