Categorized | Biocompute

Perl chomp函数

Posted on 04 十一月 2009 by 柳城 ,阅读 901

PPS:学习Perl语言编程中……,打算边学边把Perl函数整理出来。

介绍:

chomp函数通常会删除变量里包含的字符串尾部的换行符。它是chop函数的一个略微安全些的版本,因为它对没有换行符的字符串没有影响。更准确地说,它根据了解$/的当前值删除字符串终止符,而不只是最后一个字符。

和chop不同,chomp返回删除的字符数量。你不能chomp一个直接量,只能处理变量。

用法:

chomp VARIABLE

chomp LIST

chomp

例子:

#!/usr/bin/perl

$string1 = "This is test";
$retval  = chomp( $string1 );

print " Choped String is : $string1\n";
print " Number of characters removed : $retval\n";

$string1 = "This is test\n";
$retval  = chomp( $string1 );

print " Choped String is : $string1\n";
print " Number of characters removed : $retval\n";

结果如下:

 Choped String is : This is test
 Number of characters removed : 0
 Choped String is : This is test
 Number of characters removed : 1

chomp函数 完~

转载请注明 : 来源于 Perl chomp函数 | 柳城

赞助商

4条评论 于 “Perl chomp函数”

  1. Blinux Blinux Says:

    /呲牙

    [回复]

  2. 老饕 老饕 Says:

    Perl有所耳闻~~仅此~呵呵

    [回复]

    Lc.
    Lc. 回复:

    不用学更好嘛.. 偶是工作需要嘛~~ :)

    [回复]

  3. 第三眼 第三眼 Says:

    读取外部文件时的必备函数~

    [回复]

Leave a Reply

广告招租

[强] [握手] [可爱] [ok] [呲牙] :) [偷笑] [流泪] [疑问] [亲亲] [擦汗] [得意] [衰] [可怜] [抱拳] [坏笑] more »

无觅相关文章插件,快速提升流量