--On Wednesday, August 06, 2003 2:50 PM +0200 Jenda Krynicky <[EMAIL PROTECTED]> wrote:
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
If it's the case that the end-of-order marker is a constant string, it can be a little shorter:
$/="ORDER END MARKER\n"; while (<DATA>) { chomp; my %order = split /\n|:\s*/; save_order( \%order ); }
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]