读文件建议用while,用for是不是太繁琐了,效率还不高
2009/7/16 Excel Chen <[email protected]>
>
> Kevin_li,Joe jiang, thanks.
>
> %word=();
> @file=();
>
> open (DATA,"test.data")|| die $! ;
>
> @line=<DATA>;
>
> for ($index=0;$index<@line;$index++){
>
> @file=split /:/,$line[$index],2;
> $word{$file[0]}=$file[1];
>
> }
> while (($key,$value)=each(%word)){
> print "$key\n";
>
> }
>
> close (DATA);
>
> Thanks all. Plz give me some suggestion for up.
>
>
> On Jul 14, 9:31 pm, kevin_li <[email protected]> wrote:
> > $a='1:22:3';
> > $a=~/(.*?):(.*)/;
> > print "$1\n";
> > print "$2\n";
> >
> > On 7月15日, 下午12时16分, Excel Chen <[email protected]> wrote:
> >
> >
> >
> > > 我打开文件test.data 内容如下:
> > > text1.txt:http://google.com
> > > pts2.txt:http://google.com
> > > rtxhand.txt:googlefile.
> >
> > > 我的目的:把每行第一个:符号之前的字符串赋给一个hash数组的key.
> >
> > > 请问如何匹配?
> >
>
--
态度决定高度,技术成就梦想
--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。
要在此论坛发帖,请发电子邮件到 [email protected]
要退订此论坛,请发邮件至 [email protected]
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---