小编dip*_*pot的帖子

如何使用当前文本行中的关键字来搜索Perl中已读取文本的前一行?

我开始在Perl中,并在while循环中逐行解析一些文本,但无法找到有关此特定问题的帮助.我想使用当前文本行中先前读取的文本行的信息.

我的代码如下:

while(<data>){

    my $message = substr $_, 0, 1;

    if ($message eq 'A'){

        my $order_ref  = substr $_,  1, 9;
        my $order_book = substr $_, 20, 6;

        push @add_orders, $_;
        print add_order_file "$order_ref,$order_book\n";
    }
    if ($message eq 'X'){

        my $order_ref = substr $_, 1, 9;
        #now I would like to use order_ref to look up order_book from a previous line of text 
        # where the message is equal to A, 
        my $order_book = LOOKED UP VALUE FROM PREVIOUS TEXT; …
Run Code Online (Sandbox Code Playgroud)

perl text-parsing

1
推荐指数
1
解决办法
94
查看次数

标签 统计

perl ×1

text-parsing ×1