#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw/fatalsToBrowser/; use Data::Dumper; my $q = new CGI; my $result = ParseEDI( { EDI => '/path/to/edis/invoice.edi', DIC => '/path/to/dics/d93a_invoic.dat', } ); print $q->header, $q->start_html, $q->start_pre; print Dumper $result; print $q->end_pre, $q->end_html; sub ParseEDI { my $self = shift; my $output = { EDI => undef, # Original message PDS => undef, # Perl Data Structure }; open ( EDI, "<", $self->{EDI} ) or die ( "Error opening EDI message"); my $i = 1; while ( ) { $output->{EDI} .= $_; my ($CODE, $VARS) = ($_ =~/^(\w{3})\+(.*)'$/); $output->{PDS}->{$i} = { CODE => { TAG => $CODE, DES => DataIndex( { DIC => $self->{DIC} } )->{$CODE}, }, SEG => [map ([map ($_ , split /:/)] , split /\+/ , $VARS)], }; $i++; } close ( EDI ); return $output; } sub DataIndex { my $self = shift; open (DIC, "<", $self->{DIC} ) or die "Error opening the data index"; my $res = {}; while () { my ($CODE, $DESC) = ($_ =~/^(\w{3}) (.*)$/ ); $res->{$CODE} = $DESC; } close DIC; return $res; }