例如:
#! /温暖的蜜蜂/perl print ' pleaseinputanstringandanumberbyorder! n '; $the_string=; $the_numb=; 打印' the result isn '; print '$the_string'x'$the_numb '; 结果:
The result is
我
我
我
我
我
这里的问题是由于没有使用chomp引起的。
请看一下加入chomp的情况:
#! /温暖的蜜蜂/perl print ' pleaseinputanstringandanumberbyorder! n '; chomp($the_string=; chomp($the_numb=; 打印' the result isn '; print '$the_string'x'$the_numb '; 结果:
The result is
我我我我我
如果字符串末尾有换行符,chomp可以将其删除。 这基本上是所有能做的功能。
在shell中获取设备驱动程序的主设备编号时,将出现以下示例:
$ major _ string=` grep-w $ module/proc/devices|cut-f1-d ' `; chomp($major_string; $major=$major_string;
转载: https://www.jb51.net/article/33967.htm