Perl 中的 chomp函数

首页 / Perl入门教程 / Perl 中的 chomp函数

描述

此更安全的印章版本将删除任何与$/当前值相对应的结尾字符串(在英语模块中也称为$INPUT_RECORD_SEPARATOR)。它返回从其所有参数中删除的字符总数。默认情况下,$/设置为换行符。

语法

以下是此函数的简单语法-

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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

OAuth 2.0实战课 -〔王新栋〕

Selenium自动化测试实战 -〔郭宏志〕

重学线性代数 -〔朱维刚〕

爱上跑步 -〔钱亮〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

手把手带你写一门编程语言 -〔宫文学〕

超级访谈:对话张雪峰 -〔张雪峰〕

深入拆解消息队列47讲 -〔许文强〕

AI绘画核心技术与实战 -〔南柯〕

好记忆不如烂笔头。留下您的足迹吧 :)