Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!rpi!zaphod.mps.ohio-state.edu!usc!ucsd!ames!haven!uvaarpa!mmdf From: frech@mwraaa.army.mil (Norman R. Frech CPLS) Newsgroups: comp.lang.perl Subject: source code Message-ID: <1990Jun6.004442.14479@uvaarpa.Virginia.EDU> Date: 6 Jun 90 00:44:42 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: frech@mwraaa.army.mil Organization: The Internet Lines: 73 Greetings, I am fairly new to perl and the following is a program which I developed to read a file off an ibm and convert the packed values to something usable. It then writes the data down in delimited form for dbaseiii. The program seems to work but I have a feeling it is a terrible hack and would appreciate some kind criticism or possible improvements, etc. Thanks, Norm Frech *** cut here *** @lookup[0] = ('{}0'); @lookup[1] = ('AJ1'); @lookup[2] = ('BK2'); @lookup[3] = ('CL3'); @lookup[4] = ('DM4'); @lookup[5] = ('EN5'); @lookup[6] = ('FO6'); @lookup[7] = ('GP7'); @lookup[8] = ('HQ8'); @lookup[9] = ('IR9'); while (<>) { chop; $field1 = substr($_,0,5); $field2 = substr($_,5,13); $field3 = substr($_,18,4); $field4 = substr($_,22,40); $field5 = substr($_,62,1); $field6 = substr($_,63,1); $field7 = substr($_,64,3); $onhand = substr($_,67,9); $stock_val = substr($_,76,9); $field8 = substr($_,85,9); $field9 = substr($_,94,1); $field10 = substr($_,95,5); # ship two values to be whack $onhand = &packibm($onhand); $stock_val = &packibm($stock_val); # print the values print "\"",$field1,"\"\,\"",$field2,"\"\,\"",$field3,"\"\,\""; print $field4,"\"\,\"",$field5,"\"\,\"",$field6,"\"\,\"",$field7; print "\"\,",$onhand,"\,",$stock_val,"\,",$field8; print "\,\"",$field9,"\"\,\"",$field10,"\"\n"; } sub packibm { local($value) = @_; $len = length($value); $tend = substr($value,0,$len - 1); $lval = substr($value,$len - 1,1); $get = &calval($lval); if ($i < 10) { return($tend * 10 + $i); } else { return($tend * 10 * -1 + (($i - 10) * -1)); } } sub calval { for ($i = 0; $i < 10; $i++) { for ($j = 0; $j < 3; $j++) { $look = substr(@lookup[$i],$j,1); if ($lval =~ $look) { if ($j == 1) { $i = $i + 10; } return $i; } } } } *** cut here ***