mazelmiler
高手请进 求 perl 分隔字符串的方法,其中分隔符不是一种
例如 a b c"/t"d"/t"e"/n"f"/n"
分析完后得到如下:
@a 里面有a b c d e f
我试过@a = split(/"/t"|"/r/n"|" "/, $value); 是不行的
在线急等啊
converse
[code]
$text = 'a b c"/t"d"/t"e"/n"f"/n"';
@array = split/ |/"//t"|/"//n"/, $text;
foreach (@array)
{
print $_, "/n";
}
[/code]
converse
这种情况下,还是找本入门书好好看看,病急乱投医,别人说了你也不一定懂.
Lonki
[quote]原帖由 [i]mazelmiler[/i] 于 2008-7-3 10:07 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8726068&ptid=1187147][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]
/s到是接近但是如果例如这样
a 空格空格 b 回车 c 缩进缩进缩进缩进 d 空 e 回车回车 f
这样的话会出现N多空值 [/quote]
my @words = split //s+/, $str;
另外, 如果你要提取的字符比较规律的话, 可以考虑正则:
类似my @words = $str =~ //w+/g;
cdkrr
[quote]原帖由 [i]mazelmiler[/i] 于 2008-7-3 10:24 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8726236&ptid=1187147][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]
因为我在判断$_是否为空时总是出错Use of uninitialized value in numeric eq (==) at readXml.pl line 76.
我是这样写的
foreach (@a){
# print;
if($_==u ... [/quote]
用eq 代替== 应该就可以了。