Re: [問題] 陣列

作者: dryman (dryman)   2013-03-06 04:08:18
#!/usr/bin/env perl
use 5.010;
while ($_=<DATA>) {
if (/^name \w+/){
say $&; # 比對到的字串
$_ = <DATA>;
@specs = split;
shift @specs;
$_ = <DATA>;
@value = split;
say "spec $_\nvalue ", $value[1] for @specs;
say "";
}
}
__DATA__
name a1b1c1
spec aaa1 bbb1 ccc1
value 500
name a2bc
spec aaa2
value 600
name ab2c
spec bbb2
value 550
name d3e3
spec ddd3 eee3
value 230
作者: hws110 ( only you )   2013-03-06 10:18:00
您好,請問use 5.010是perl的版本嗎?我的是5.8版
作者: dryman (dryman)   2013-03-06 22:49:00
用5.8把say換成printf還有加上"\n"就行了
作者: hws110 ( only you )   2013-03-06 23:21:00
您好,我也是這樣改的,感謝您的回答

Links booklink

Contact Us: admin [ a t ] ucptt.com