slugger415 has asked for the wisdom of the Perl Monks concerning the following question:
Hello all, I'm seeing some confusing behavior with <STDIN> in my script (on Win 10 / Strawberry Perl), prompting for user input.
print "song: $string\n Correct? y/n: "; my $res = <STDIN>; chomp($res); if($res =~ /n/i){ print "Enter correct text: "; $str = <STDIN>; chomp $str; print "new: ", $str, $/; } print "str: ", $str, $/; my $newfile = "$str.mp3"; print "newfile: $newfile\n";
The output looks like this, if I enter 'ssss' as STDIN:
song: Fossil Aerosol Mining Project - Nu Message Correct? y/n: n Enter correct text: ssss new: sssss str: sssss .mp3ile: ssss
Note on the last line that ".mp3" jumps to the beginning of the line in the output (and variable value doesn't include it). That is, it should print "newfile: ssss.mp3". Any ideas what I'm doing wrong? Thanks as always.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange behavior with STDIN
by kcott (Archbishop) on Oct 26, 2021 at 01:10 UTC | |
by slugger415 (Monk) on Oct 26, 2021 at 16:56 UTC | |
by ikegami (Patriarch) on Oct 26, 2021 at 19:26 UTC | |
|
Re: Strange behavior with STDIN
by LanX (Saint) on Oct 26, 2021 at 00:57 UTC | |
by ikegami (Patriarch) on Oct 26, 2021 at 19:30 UTC | |
by LanX (Saint) on Oct 26, 2021 at 19:57 UTC | |
by slugger415 (Monk) on Oct 26, 2021 at 16:58 UTC | |
by LanX (Saint) on Oct 26, 2021 at 20:24 UTC | |
|
Re: Strange behavior with STDIN
by slugger415 (Monk) on Oct 26, 2021 at 00:35 UTC |