Perl 编程/关键字/split
外观
split拆分EXPRESSION为字符串列表,并返回此列表。没有EXPRESSION, $_被用作源。在EXPRESSION匹配PATTERN被视为分隔符,它可能超过一个字符,甚至可以是零长度(结果为零宽度匹配)。在分割EXPRESSION时,分隔符本身不会被添加到字符串中。
split /PATTERN/, EXPRESSION, LIMIT
split /PATTERN/, EXPRESSION
split /PATTERN/
split
print
$login = "anton";
$passwd = "j4\/D\\S";
$uid = 1721169842;
$gid = 8421691721;
$gcos = "nothing";
$home = "\\";
$shell = "ksh";
$rec = join(':', $login, $passwd, $uid, $gid, $gcos, $home, $shell);
print $rec, "\n", join(':', split('8', $rec)), "\n";
split 返回冒号分隔的字符串元素,其中 “8” 也作为分隔符
anton:j4/D\S:1721169842:8421691721:nothing:\:ksh anton:j4/D\S:1721169:42::421691721:nothing:\:ksh