PPPPPS:学习Perl语言编程中……,打算边学边把Perl函数整理出来。
介绍:
chop函数会砍掉字符串变量的最后一个字符,并返回砍掉的字符。chop函数不管字符串里是什么都会剪短它,而chomp函数则更有选择性一些。
不能chop直接量,只能chop变量。
用法:
chop VARIABLE chop LIST chop
例子:
如果chop一列LIST变量,那么列表中的每个字符串都会被剪短:
@lines = `cat myfile`; chop @lines;
在最常见的情况下,chop可以用substr来表示:
$last_char = chop($var); $last_char = substr($var, -1, 1, ""); # 同上
再来看下面的完整的例子:
#!/usr/bin/perl $string1 = "This is test"; $retval = chop( $string1 ); print " Choped String is : $string1\n"; print " Character removed : $retval\n";
结果:
Choped String is : This is tes Number of characters removed : t
Perl chop函数 完~~
《 “Perl chop函数” 》 有 9 条评论
函数名字很形象,斩 /呲牙
哈哈.是啊~~ 你一说我才意识到
什么作用呢?
相当于asp和php的trim函数哦 :)
python 也是很适合生物信息学的吧,什么时候也学学python
等perl学会了。学学python也不错。
[…] Perl chop函数 […]
嗯,还是从基础学起,补着及,慢慢学吧 学了都是自己的
文章写的很详细!