Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: source code Message-ID: <1990Jun6.022140.13168@iwarp.intel.com> Date: 6 Jun 90 02:21:40 GMT References: <1990Jun6.004442.14479@uvaarpa.Virginia.EDU> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 68 In-Reply-To: frech@mwraaa.army.mil (Norman R. Frech CPLS) In article <1990Jun6.004442.14479@uvaarpa.Virginia.EDU>, frech@mwraaa (Norman R. Frech CPLS) writes: | 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. Here's what I could do in 15 minutes. Might be a few typos. Caveat Executor. I tried to keep your logic and order (had to, with that time limit), but part of the work is learning to "Think Perl". ################################################## cut here @lookup = split(/ /,'{}0 AJ1 BK2 CL3 DM4 EN5 FO6 GP7 HQ8 IR9'); while (<>) { chop; ($f1,$f2,$f3,$f4,$f5,$f6,$f7,$onhand,$stock_val,$f8,$f9,$f10) = /^(.{5})(.{13})(....)(.{40})(.)(.)(...)(.{9})(.{9})(.)(.{5})/; # ship two values to be whack $onhand = &packibm($onhand); $stock_val = &packibm($stock_val); # print the values print '"', join('","', $f1, $f2, $f3, $f4, $f5, $f6, $f7, $onhand, $stock_val, $f8, $f9, $f10), '"', "\n"; } sub packibm { local($_) = @_; local($tend,$lval) = /(.*)(.)/; local($get) = &calval($lval); if ($get < 10) { ## meant $get instead of $i, I hope return($tend * 10 + $get); ## ditto } else { return($tend * 10 * -1 + (($get - 10) * -1)); ## ditto } } ## there is something very non-perlish about the following code, but ## I couldn't reverse engineer it in the few minutes I had to do this. ## Larry? sub calval { local($i,$j); 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 print substr("Of course, I'm Just another Perl hacker,",-25,25); -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/