Multiline Parsing

Discussion in 'Perl Misc' started by banker123, Nov 29, 2006.

  1. banker123

    banker123 Guest

    I have the following code that parses lines that contain \s{8}\d{5} and
    assigns invoice as a variable, the elsif parses lines that contain
    \s\sBatch: and assign the batch and seq to a hash. This code works
    when I have one invoice, however the code breaks (does not parse the
    second invoice) when more than one invoice is present.

    my %batches;
    while ( <DATA> ) {
    if (/\s{8}\d{5}/) {
    $invoice = substr($_,32,14);
    }
    elsif (/\s\sBatch:/ ) {
    $batch = substr($_,9,8);
    $seq = substr($_,22,4);

    $batches{ $batch } = {

    seq => $seq,
    invoices => [],
    };

    print "$batch $seq $invoice\n";
    }

    push @{ $batches{ $batch }{ invoices } }, $invoice;

    }

    $batches{ $batch }{ seq } and @{ $batches{ $batch }{ invoices } }

    DATA INVOICE
    BOBS FOODS 352491 $42.50
    $942.50
    Batch: 00608623 Seq: 17 352650 $900.00
    Check Serial: 880587
    banker123, Nov 29, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    858
    GIMME
    Feb 11, 2004
  2. Uwe Ziegenhagen
    Replies:
    5
    Views:
    7,583
    oceamus
    Jan 27, 2010
  3. Brad Johnson

    Multiline command line parsing

    Brad Johnson, Sep 19, 2007, in forum: Python
    Replies:
    0
    Views:
    326
    Brad Johnson
    Sep 19, 2007
  4. arby

    parsing multiline textbox

    arby, Feb 21, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    141
  5. dale zhang
    Replies:
    8
    Views:
    398
    Tintin
    Nov 30, 2004
Loading...

Share This Page