Mega Code Archive

 
Categories / Perl / String
 

Chop function deletes the character at the right end of the line of text

When you type a number 10 and press Enter, the line of input assigned to $originaldist consists of three  characters: the 1, the 0, and a newline character.  #!/usr/local/bin/perl    print ("Enter the distance to be converted:\n");  $originaldist = <STDIN>;  chop ($originaldist);  $miles = $originaldist * 0.6214;  $kilometers = $originaldist * 1.609;  print ($originaldist, " kilometers = ", $miles," miles\n");  print ($originaldist, " miles = ", $kilometers, " kilometers\n");