join and split
时间:2005-04-20 来源:寂寞烈火
join用于将表中的元素连接成串,split是串拆分成表
join语法:
join EXPR,LIST
如:
/home/lee#perl -e 'print ("a","b","c");print " "'
abc
/home/lee#perl -e 'print join("=>","a","b","c");print " "'
a=>b=>c
/home/lee#perl -e 'print join(":","a","b","c");print " "'
a:b:c
join函数让EXPR中的值包围着LIST里的串,然后返回整个串!EXPR也可以拥有多个字符!
split语法:
split
split /PATTERN/
split /PATTERN/,EXPR
split /PATTERN/,EXPR,LIST
这里,split函数在串PATTERN出现的每个地方将串EXPR分开.例子:
/home/lee#perl -e 'print ((split " ","hello world")[1]);print " "'
world
相关阅读 更多 +