"Graham Foster" <graham / inca.freeserve.company.unitedkingdom> writes:

>> Years ago, on a job developing custom reporting software, this was 
> one of the
>> side tasks.  Parsing a report may sound boring, but I urge you to 
> at least
>> download this report and peek inside.  It's a tragic example of 
> database output
>> gone wrong.
>
> No responses yet???? Too difficult?? Pity - as a Newbie I was 
> interested to see how the experts handled this one.
> Graham

Well, here is my try.  I wonder if that does it?


salesperson = customer = sortcode = "(undefined)"

$, = ";"

IO.readlines("period2-2002.txt").each { |line|
  case line 
  when /  Salesperson  (.*)/
    salesperson = $1
  when /  Customer  (.*)/
    customer = $1
  when /  SA Sort Code  (.*)/
    sortcode = $1
  when /^[0-9A-Z][0-9A-Z.-]+ .*\d+  .*\d+  /
    name, numbers = line[0..41], line[41..-1]

    numbers.gsub! ',', ''
    numbers.gsub! '%%%+', '0'
    
    print salesperson, customer, sortcode,
          *(name.strip.split(/  +/) + numbers.split(/ (?: +|(?=[-\d]))/))
  end
}


-- 
Christian Neukirchen  <chneukirchen / gmail.com>  http://chneukirchen.org