當前位置:首頁 » Perl » Perl chomp()函數

Perl chomp()函數

perl chomp()函數,chomp()函數學習例子,chomp()函數實例代碼,chomp()函數教學等

語法

chomp VARIABLE

chomp( LIST )

chomp


定義和用法

這更安全的版本的印章刪除任何尾隨的字符串,對應的當前值$/(也稱為$ INPUT_RECORD_SEPARATOR在英文模塊)。它返回的總數從它的所有參數的字符。默認情況下$/設置為新行字符。

返回值

  • 整數,所有字符串中刪除的字節數

例子

#!/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 );
#by www.gitbook.net
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