August 18, 2010

I Hate EDI

Why can't people just use XML? Seriously. Seriously. Perl headaches.

sub ParseOrder {
  foreach (@_) {
    if (/^[ \t]*PRODUCT[ \t]*:[ \t]*/) {
      &GetUPC(&Trim($'));
    }
    elsif (/^[ \t]*PURCHASE[ \t]*ORDER[ \t]*:[ \t]*/) {
      if ($' =~ m/^([0-9]*)/) {
        print $1 . "\n";
      }

      if ($' =~ /[ \t]*PO[ \t]*DATE[ \t]*:[ \t]*/) {
        print $';
      }
    }
  }
}

1 comment:

Babelabout said...

Indeed, you should use XPath in order to extract information from your EDI document ;-)

Of course, you would need to first XML-ized your EDI. I am currently working on http://parse-EDIFACT.net/, it should be ready soon...