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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.