in reply to Re^10: How best to strip text from a file?
in thread How best to strip text from a file?
Hi, bobdabuilda!
Am glad this is shaping up for you, and I think you've done well building on to this...
Here are a few items for you to consider...
Use another hash to keep track of previously-seen Orders. Without re-posting the entire code, here's what you can add to make this functional:
Add a %seen hash:
my ( @records, @orders, %seen );
Add a RECORD: label at the start of the line, in front of the for that iterates through each record (Order):
RECORD: for my $record (@records) { ...
Finally, use an if() statement to process the Order ID (instead of a single line like with the other fields):
if (/Order ID:(\S+)/) { next RECORD if $seen{$1}; $seen{$1}++; $hash{orderID} = $1; }
I suspect you can see what this does, but if an Order ID: match is found, it first checks to see if the ID's already been 'seen.' If so, it gets the next record for processing, else it tags the Order as seen and sets the hash.
Write to your Excel file from within your subroutine. 1) You've got a complete record by the time the subroutine is called in the script (see its current position). You can send your subroutine the row number:
writeToSpreadSheet( $row, \%hash );
Then, in the subroutine:
sub writeToSpreadSheet { my ($row, $hashReference) = @_; ...
2) By writing to the Excel spread sheet from within the subroutine, you're somewhat modularizing your program by keeping its functionality separate.
Let me know how your spread sheet writing is going or if you encounter any other issues...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^12: How best to strip text from a file?
by bobdabuilda (Beadle) on Nov 13, 2012 at 03:54 UTC | |
by Kenosis (Priest) on Nov 13, 2012 at 04:30 UTC | |
by bobdabuilda (Beadle) on Nov 13, 2012 at 05:38 UTC | |
by Kenosis (Priest) on Nov 14, 2012 at 03:33 UTC |