in reply to Modules?
in thread COBOL Layout parsing

What are we talking about? Show us the code. Well, ok.

Is this what usage could look like?

DISCLAIMER
The COBOL might be a bit rusty (1987) and the perl is definitely a little speculative :-) so if I made mistaeks please correct them, but do not bother to check matching ({[< and the like - I didn't - the code is not meant to be run yet. It is meant to illustrate the questions and comments below the code.

#!/usr/bin/perl -w # ModuleWithAcceptableNameThatReflectsThePurpose Q1 use COBOLstorage; $datafile="somepathtothedata.coboldata"; $COBOLrecord = <<'FD1'; # C1 * paymenttrack-file 01 Payment. 03 Rec-id pic X(6) value "PAY001". 03 Date pic X(10) value spaces. 03 EEEE-MM-DD Redefines Date. 05 EEEE pic 9999. 05 FILLER pic X. 05 MM pic 99. 05 FILLER pic X. 05 DD pic 99. 03 Amount pic 9(12)V99 comp-3 value zeroes. 03 Currency-code pic XXX value spaces. 03 Description. 05 Desc-line occurs 4 pic X(50) value spaces. 03 Originator. 05 Ident-type-code pic x value spaces. * 'P' Natural person * 'B' Business * 'N' National/Local Gov Agency * 'S' Supranational Agency 05 Ident. 07 Accountnumber pic 9(10) comp-3 value zeroes. 07 N-Name. 09 Familyname pic X(36) value spaces. 09 Title pic X(6) value spaces. 09 Initials pic X(6) value spaces. 09 FILLER pic X(10) value spaces. 07 O-Name redefines N-Name. 09 OrganisationName pic X(48). 09 Contact-nick pic X(10). 07 Address. 09 Street pic X(48) value spaces. 09 Nr pic X(8) value spaces. 09 Postal-code pic X(7) value spaces. 09 Country-code pic XX value spaces. 03 Beneficiary. 05 Ident-type-code pic x value spaces. * 'P' Natural person * 'B' Business * 'N' National/Local Gov Agency * 'S' Supranational Agency 05 Ident. 07 Accountnumber pic 9(10) comp-3 value zeroes. 07 N-Name. 09 Familyname pic X(36) value spaces. 09 Title pic X(6) value spaces. 09 Initials pic X(6) value spaces. 09 FILLER pic X(10) value spaces. 07 O-Name redefines N-Name. 09 OrganisationName pic X(48). 09 Contact-nick pic X(10). 07 Address. 09 Street pic X(48) value spaces. 09 Nr pic X(8) value spaces. 09 Postal-code pic X(7) value spaces. 09 Country-code pic XX value spaces. FD1 open(IN,$datafile); associate($blurk,$COBOLrecord); # Q2; my $total = 0; while(<IN>) { $blurk = $_; #========== this is where the module magic should take effect: # we can now use the COBOL data-item in perl. if ( $Description =~ /(?:salary|gage)/i ) { if ($Beneficiary.ident-type-code ne 'P') { # Q3 print << "WARNING"; # C2 Check this! Salary paid to organisation?: On $Date $Originator.Accountnumber paid $Beneficiary.A +ccountnumber $Currency-code $Amount BENY: $Beneficiary.Organisation +Name $Beneficiary.Contact-nick \"$Description\"\n" WARNING } else { $total{$Currency-code} += $Amount; } } } print "Total salaries / gages in USD $total{"USD"} \n";

So here is the preliminary list of questions:

The example leaves a lot of questions unanswered:

... we can only start at one place at a time. Maybe you could reflect on this, or on your vision of how you would name / use this module.

HTH,

      Danny

Replies are listed 'Best First'.
Re: Re: Modules?
by Anonymous Monk on Nov 06, 2002 at 21:05 UTC
    This would be useful, the idea being that "I've got a copylib member, I've got a data file, I just want to process it in Perl". I have done this quite a bit in the past, but always make up my own data storage, parsing code, etc. Q1: maybe IO::COBOL ??? Q2: Not sure if I agree with your assumptions, here. My own take on such a module would be the ability to do something like
    IO::COBOL::ReadData($FILEHANDL, $COBOLRecord); IO::COBOL::WriteData($OUTFILEHANDL, $COBOLRecord);
    Q3: Omygod, I'm not ready for Perl6 Other: Why not just add subscripts to the (target) data variables for an OCCURS statement? 88 levels are just Static symbols. I would assume that all data has already been translated to ASCII encoding in order to use this. Are you working on something? I can work on it if you don't have anything yet (although I've never written a CPAN module before). ... HH