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