programming-examples/perl/String/Cleaning Up Typed Input.pl
2019-11-15 12:59:38 +01:00

22 lines
507 B
Perl

#Input that you read from STDIN includes everything the user typed, including the newline character at the end.
#To get rid of that newline, you can use the chop or chomp functions.
chop VARIABLE
chop LIST
chop
This function chops off the last character of a string and returns the character chopped.
If VARIABLE is omitted, chop chops the default variable $_.
For example, look at this script:
while (<>) {
print;
}
You chop the input.
while (<>) {
chop;
print;
}