Mega Code Archive

 
Categories / Perl / String
 

Cleaning Up Typed Input

#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; }