- Reading from files
- Input operator <> reads one line from
the file, including the newline character
- chomp will remove newline if you want
- Can modify input recorder separator $/ to read
characters, words, paragraphs, records, etc.
print "What type of pet do you have? ";
my $pet = <STDIN>; # Read a line from STDIN
chomp $pet; # Remove newline
print "Enter your pet's name: ";
my $name = <>; # STDIN is optional
chomp $name;
print "Your pet $pet is named $name.\n";
What type of pet do you have? parrot
Enter your pet's name: Polly
Your pet parrot is named Polly.
|