Perl解析具有更改的字段大小的多行文件

| 我对此很困惑。我正在尝试解析具有如下数据的文件:
\"1111 Some random descriptive text can have numbers and letters\",
// :property1.Some description
// :property2.A different description
// :property3.Yet another
\"2222 More random text here\",
// :property1.Some description
// :property1.A different description
// :property2.Yet another description
// :property3.Yet another
我将解析它并创建html文件。 我现在做完后在数组中:
@array = <FILE>;

#Put it in a single long string:
$long_string = join(\"\",@array);

#Then trying to split it with the following regex:
@split_array = split(/\\\"\\d{4}.+\",/,$long_string);
我打算以某种方式保存匹配字符串,并以某种方式将其与属性字段相关联... 现在真的很怀疑我的方法。     
已邀请:
        解析文本时,您需要确定关键的杠杆作用点,以帮助您将一条信息与另一条信息区分开。这是我在您的文字中看到的内容: 每行是一个不同的单元。 有些行以
//
开头,而有些则不是。 行的开头有一定的规律性,而其余的则有很多可变性。 通过将文档放到一个单独的字符串中,可以削弱这些杠杆作用。 另一个关键的解析策略是将事情分解为简单易懂的步骤。同样,在这种情况下,针对一个巨型字符串运行一个正则表达式通常是错误的方向。 这就是我的开始方式:
use strict;
use warnings;

open(my $file_handle, \'<\', \'input_file_name\') or die $!;

while (my $line = <$file_handle>){
    if ( $line =~ /^\\\"(\\d+)/ ){
        my $number = $1;
        ...
    }
    else {
        ...
    }
}
    

要回复问题请先登录注册