Perl-chomp

chomp


FUNCTION: 用于移除字符串结尾的换行符,除非有特殊原因,一律对输入值进行chomp
#!perl
#Learing Perl 
#Chapter 2
#Exercise2_2
#Written by HEWEI
#Date:2011 03 22
########################
#User input the value 
print "Please input the value of radius\n";
$radius = <STDIN> ; #这里是读入用户输入信息,但是用户按ENTER的符号也读进去了
#chomp($radius = <STDIN>) ;
print "The radius is $radius\n";
#########################
#define Scalar Variable
$pi=3.141592654;
########################
#Calculate the value of circumference
$cir=2*$pi*$radius;
#######################
#print the result
print "The radius is $radius result is $cir.\n";

#end

输出结果:
Please input the value of radius
12.5
The radius is 12.5
The radius is 12.5      这里有一个换行符
  result is 78.53981635.

更改程序:
#$radius = <STDIN> ; #这里是读入用户输入信息,但是用户按ENTER的符号也读进去了
chomp($radius = <STDIN>) ;

输出结果:
Please input the value of radius
12.5
The radius is 12.5
The radius is 12.5 result is 78.53981635.

你可能感兴趣的:(C++,c,C#,perl)