Hello, This is kind of sloppy, but it is what I have been able to come up with. How can I make this more "cleaner"?
The data lines and output are at the end of this mail. Thank you all. #!/opt/local/bin/perl #..................End include subroutines ................ &check_arguments($#ARGV); #verify command line &process_arguments(@ARGV); #input file = $opt_i #output file = $opt_o &open_file("INFILE", "", "$opt_i"); #update mode my(%MAIN_ADD_DECK)= (); # ~~~~~~~~~~~ READING OF INPUT FILE BEGINS HERE ~~~~~~~~~~ while ($line = &read_from_file("INFILE")) { next if ( (!($line =~ /f.\d{9}\../i )) || $line =~ /^\s*--/ ); # weedout comment & non data lines chomp $line; #remove end of line marker if ( $line =~ /--/ ){ split /--/, $line, 2;$line = join '', $_[0]; } if ( $line =~ /\&\&/ ){ split /\&\&/, $line, 2;$line = join '', $_[0]; } $line =~ s/\s+//g; #finally squeeze out spaces $line =~ s/new|set//i; #... tag family head to members ONLY if you encounter = ($family_head, $line)= split /=/, $line, 2 if ( $line =~ /=/); #tag family head to members push @{ $MAIN_ADD_DECK{$family_head} }, "$line"; } close INFILE; &open_file("OUTFILE", "", ">$opt_o"); #update mode foreach $family (sort (keys %MAIN_ADD_DECK )){ print OUTFILE "$family = {", @{ $MAIN_ADD_DECK{$family} }, "}\n"; } close OUTFILE; #::::::::::::::::::: SUBROUTINES ::::::::::::::::::::::::::: sub check_arguments{ local ($num_args) = @_; if ( $num_args < 3 ){ #i.e., 0 1 2 3 &error_messages; } } #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # ..........displays appropriate error messages ........... sub error_messages{ print("\n\n\n\n E R R O R\n"); print("\n\n USAGE: $0 -i {excel filename} -o {output filename }"); print("\n\n EG: $0 -i table1a.xls -o table1a.txt\n\n"); print("\n\n - E X E C U T I O N S U P P R E S S E D ! ! ! - \n\n"); print ("\a\n\n\n"); exit (1); #++ failure } #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # .......... distinguish b/n input/output files ........... #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sub process_arguments #determine -d -f -q { #require 'getopts.pl' ; # do is better than require do 'getopts.pl' || die "\n\n\n\a\tCOULD NOT LOCATE getops.pl\n\n\n" ; &Getopts('i:o:'); #similar to getopts #in sh, but better if ( !defined($opt_i) || !defined($opt_o) ){ &error_messages; } } #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # ................ open file as sepcified ................. sub open_file { local ($filevar, $filemode, $filename) = @_; open ($filevar, $filemode . $filename) || die("\a Can't open $filename"); } #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #................. read fron input file ................... sub read_from_file { local ($filevar) = @_; <$filevar>; } # ................ print to output file.................... sub print_to_file { local ($filevar, $line) = @_; print $filevar ($line); } #===================================== END OF PROGRAM ============================ --------------------------BEGIN DATA LINES-------------------------------------- type "CALCULATIONS FOR TRANSACTION F.203 (NET INTERBANK CLAIMS) ARE COMPLETE" --****************************************************************************** --****************************************************************************** --CHKDEP -- F.204 CHECKABLE DEPOSITS AND CURRENCY -- WRITTEN BY DXB ON 10/15/90 -- SERIES OF CALCULATIONS FOR TABLE F.204 -- CHECKABLE DEPOSITS AND CURRENCY --****************************************************************************** ----------------------------------- BORROWING ---------------------------------- -- --- SCBTOTAL --- set fa713120005.q = fa713123105.q +fa713122605.q +fa713125005.q --] MONETARY AUTHORITY = US GOVT CASH & --] DEPS, FOREIGN DEPOSITS, AND CURRENCY --] OUTSIDE BANKS (FROM DEP) -- --- SCBTOTAL --- set fa903023105.q =fa723123105.q +fa713123105.q -fa313020005.q --] USG MAIL FLOAT = US GOVT DEPS AT BANKS --] (FROM DEP) AND DEPS WITH THE MONETARY --] AUTHORITY LESS TOTAL CASH BALANCES --] (FROM FISCAL ANALYSIS) set fa883011105.q = fa313011105.q +fa713011203.q --] US GOLD STOCK AND SDRS = US GOVT, EX STAB --] FUND AND MONETARY AUTHORITY ------------------------------------ LENDING ----------------------------------- set fa153020005.q =fa793120005.q -fa313020005.q -fa263020005.q -fa103020000.q && -fa113020003.q -fa133020003.q -fa213020005.q -fa443020005.q && -fa473020000.q -fa513020003.q -fa543020003.q -fa573020005.q && -fa223020003.q -fa613020003.q -fa633020003.q && -fa663020003.q -fa403020003.q -fa743020003.q -fa903029005.q && -fa603020003.q -fa643020003.q --] HOUSEHOLDS (RESIDUAL) = TOTAL LESS US --] GOVT, FOREIGN, NONFIN. --] CORP., NONCORP. NONFIN., FARM, STATE & --] LOCAL GOVT, CREDIT UNIONS, PROP & --] CASULTY INSURANCE, LIFE INSURANCE, --] PRIVATE PENSION FUNDS, STATE & LOCAL --] GOV'T RETIREMENTS, FIN. COS., MONEY --] MARKET MUTUAL FUNDS, MUTUAL FUNDS, --] BROKERS AND DEALERS, SPONSORED CREDIT --] AGENCIES, AND COMMERCIAL BANKS,BPT -------------------END DATA LINES----------------------------------------------------------------- I want to produce So that, with the following lines of codes: The script will produce: $DATA{fa713120005.q} = {fa713123105.q,fa713122605.q,fa713125005.q} $DATA{fa903023105.q} = {fa723123105.q,fa713123105.q, -fa313020005.q} $DATA{fa883011105.q} = {fa313011105.q +fa713011203.q} $DATA{fa153020005.q} = {fa793120005.q, -fa313020005.q, -fa263020005.q, -fa103020000.q, -fa473020000.q, -fa513020003.q, -fa543020003.q, -fa573020005.q,-fa223020003.q, -fa613020003.q, -fa633020003.q, -fa663020003.q, -fa403020003.q, -fa743020003.q, -fa903029005.q, fa603020003.q, -fa643020003.q} with foreach $family ( keys %DATA ){ if ( $family =~ /\d/ ){ print "$family = {", @{ $DATA{$family} }, "}\n"; } } __________________ William Ampeh -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]