From: "Morrison, Trevor (Trevor)" <[EMAIL PROTECTED]>
> What I am trying to do is to process a file that has say 1000 orders
> in it all pretty much of the same format.  I want to open up the file,
> and then using a while loop go down through all of the order
> one-at-a-time and once I have all the fields populated and I have
> reached a certain line at the end of each order write the data to the
> database.  Then have it all reset, and process the next order; and do
> this until the EOF.  That is the goal.

Seems you want something like this (untested of course):

use Switch;

my %order;
while (<IN>) {
        chomp;
        switch ($_) {
                case /^(\w+)\s*: *(.*)/ {$order{lc($1)} = $2}
                case /^ORDER END MARKER/ {
                        save_the_order(\%order);
                        undef %order;
                }
                else {print "Incorrectly formated line $.: $_\n"}
        }
}

This assumes that the order file looks somewhat like this:

        Name: John Doe
        Amount: 10
        Goods: gun XYZ-12345
        Sum: 10100
        ORDER END MARKER
        Name: John Doe
        Amount: 1
        Goods: machinegun ABC-987
        Sum: 2000
        ORDER END MARKER

The code basicaly remembers anything that looks like data and when it 
encounters the end-of-order marker it calls a subroutine with all the 
data and clears the "memory".

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to