It receives user input the first time, but prints and exits the script without letting me receive user input the second time. I tried undefining $/ in a separate block, and just seeing if I could read single line input the second time, but it does the same thing - just does the first read, then exits:#!/usr/bin/perl use strict; my $input; local $/; $input = <STDIN>; print $input; $input = <STDIN>; print $input;
this doesn't work either:#!/usr/bin/perl use strict; my $input; { local $/; $input = <STDIN>; } print $input; $input = <STDIN>; print $input;
This works though:#!/usr/bin/perl use strict; my $holdRS = $/; local $/; my $input = <STDIN>; $/ = $holdRS; print $input; my $holdRS = $/; local $/; my $input2 = <STDIN>; $/ = $holdRS; print $input2;
What is it about undefining $/ that allows me to read user input only one time? (even if I set it back to default first)#!/usr/bin/perl use strict; my @userinput = <STDIN>; foreach (@userinput) { print; } my @userinput = <STDIN>; foreach (@userinput) { print; }
In reply to how to read STDIN interactively by Allasso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |