Reading input (stdin)
Read what you type in the IDE's Input tab with <STDIN> and chomp.
Runs in Zerethon IDE · Perl 5.40
Official Perl documentation ↗
A run cannot ask questions while it runs. Type the program's input in the Input tab before you press Run; <STDIN> then reads it one line at a time.
main.pl
use v5.40;
chomp(my $name = <STDIN>);
my ($x, $y) = split ' ', <STDIN>;
say "Hello, $name! $x + $y = ", $x + $y;
Input (stdin)
Ada 3 4
Output
Hello, Ada! 3 + 4 = 7
main.pl
use v5.40;
my $total = 0;
while (my $line = <STDIN>) {
chomp $line;
next if $line eq "";
$total += $line;
}
say "total: $total";
Input (stdin)
5 10 15
Output
total: 30
- A line read from
<STDIN>ends with its newline;chompremoves it. split ' ', $linesplits on any run of whitespace and ignores leading spaces.- At the end of the input
<STDIN>returnsundef; using it then givesUse of uninitialized valuewarnings. Add the input in the Input tab.