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...


In reply to Re^11: How best to strip text from a file? by Kenosis
in thread How best to strip text from a file? by bobdabuilda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.