close

Perl 函式 - chomp

 

■ 功  能

從字符串中刪除結尾的記錄分隔符

 

 

 

■ 語  法

chomp VARIABLE

chomp  LIST 

chomp

 

 

 

■ 用  法

chomp為更安全版的chop,只有尾巴和 $/ 值相同的字元才會被刪除。

如果 $/ 為空的,chomp會刪除後面的換行字元。

 

 

 

■ 傳  回  值

傳回刪除了多少個字元。

 

 

■ 範  例

程式碼

#!/usr/bin/perl

$STRING1 = "Starting to test";
$COUNTl  = chomp( $string1 );

print " Choped String is : $STRING1\n";
print " Number of characters removed : $COUNTl\n";

$STRING2 = "Starting to test\n";
$COUNT2   = chomp( $STRING2 );

print " Choped String is : $STRING2\n";
print " Number of characters removed : $COUNT2\n";

 

結果

 Choped String is : Starting to test
 Number of characters removed : 0
 Choped String is : Starting to test
 Number of characters removed : 1


#關鍵字 Perl 函式 - chomp用法;Perl 函式 - chomp語法;Perl 函式 - chomp範例;

 

 

■ Perl  其它函數

▶ Perl 函式|函數|指令集

 


arrow
arrow
    全站熱搜

    News123 發表在 痞客邦 留言(0) 人氣()