perl程序中,有时在输入过程中使用chomp才会得到正确的结果。
例子:
#!/bin/perl
print "Please input an string and a number by order!n";
$the_string=<>;
$the_numb=<>;
print "The result is n";
print "$the_string"x"$the_numb";
结果:
The result is
my
my
my
my
my
这里的问题便是没有使用chomp引起的。
来看加入chomp的情况:
#!/bin/perl
print "Please input an string and a number by order!n";
chomp($the_string=<>);
chomp($the_numb=<>);
print "The result is n";
print "$the_string"x"$the_numb";
结果:
The result is
mymymymymy