+ -
当前位置:首页 → 问答吧 → 如何用perl读取数据块里的数据

如何用perl读取数据块里的数据

时间:2011-09-02

来源:互联网

文本形式如下:
************************************
1.软件工程师
工作地点:XXX
职位性质:XXXX
职位要求:XXXXXXXXXXXXXX
2.研发工程师
工作地点:XXX
职位性质:XXXX
职位要求:XXXXXXXXXXXXXX
3.算法工程师
工作地点:XXX
职位性质:XXXX
职位要求:XXXXXXXXXXXXXX
。。。
************************************
现在我要提取工作地点在北京,职位要求里有“Linux”的职位,请问用perl如何实现?

作者: heartgoon2010   发布时间: 2011-09-02

没中文环境,lz测试下吧:
Perl code
#!/bin/perl 

using strict;


my $Index;
my %hash;

open ($fh,"file");

while (<$fh>){
    $index++ if(/^\d/);
    $hash{$index}.=$_;
}

foreach my $i (1..$index){
    print $hash{$i} if(m/工作性质:北京.*职位要求:.*Linux.*/s);
}

close ($fh);

作者: imeuyniy   发布时间: 2011-09-02

改下:
Perl code
#!/bin/perl 

use strict;


my $index;
my %hash;

open ($fh,"file");

while (<$fh>){
    $index++ if(/^\d/);
    $hash{$index}.=$_ if($_!~/*******/);
}

foreach my $i (1..$index){
    print $hash{$i} if($hash{$i}~m/工作性质:北京.*职位要求:.*Linux.*/s);
}

close ($fh);

作者: imeuyniy   发布时间: 2011-09-02