官术网_书友最值得收藏!

Methods to cut strings

The two methods—chop and chomp—have similar names but have a different sensitivity to the characters they work with. The chop method cuts out the last character of the string. The chomp method only cuts the last character if it is a newline character.

say "Text\n".chomp; # Text
say "Text\n".chop; # Text

say "Text".chomp; # Text
say "Text".chop; # Tex

Another group of methods—trim, trim-leading, and trim-trailing—cuts the spaces at the beginning and/or end of the string. Consider the following code snippet:

my $s = ' word '.trim;
say "[$s]"; # [word]

$s =
' word '.trim-leading;
say "[$s]"; # [word ]

$s =
' word '.trim-trailing;
say "[$s]"; # [ word]
主站蜘蛛池模板: 翁源县| 镇平县| 灵山县| 广平县| 建阳市| 纳雍县| 汕头市| 景德镇市| 景德镇市| 庆安县| 娱乐| 南开区| 迁西县| 区。| 建水县| 嘉善县| 西乡县| 鸡东县| 长顺县| 同江市| 德州市| 松潘县| 依安县| 凤冈县| 新乐市| 武冈市| 大名县| 开化县| 岳阳县| 治多县| 五大连池市| 从江县| 怀集县| 平谷区| 即墨市| 华坪县| 太谷县| 平潭县| 张家港市| 龙南县| 缙云县|