home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4956 < prev    next >
Encoding:
Text File  |  1992-07-25  |  1.6 KB  |  51 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!msdrl!ball
  3. From: ball@msdrl.com (Richard Ball)
  4. Subject: too slowwwww....
  5. Message-ID: <1992Jul24.195547.18759@msdrl.com>
  6. Organization: Merck Research Laboratories
  7. Date: Fri, 24 Jul 92 19:55:47 GMT
  8. Lines: 41
  9.  
  10. After learning a little perl I thought I would apply it to a task I had in
  11. reformatting a postscript file. My filter, not surprisingly I guess, runs very
  12. slowly and since there are few here with interests in speed and scalability I
  13. would like to solicit suggestions for improvement.
  14. The input file looks like this
  15.  5.939 u  6.001 u mt
  16.  4.002 u  3.221 u lt
  17. [ with lots more lt type lines]
  18. s
  19.  7.845 u 1.669 u mt
  20. [etc., etc.]
  21. for about 9 or 10 K lines. What I want to do is multiply each of the numbers
  22. by a factor, strip out the u characters, strip off the t characters and convert
  23. the s to S, ie.
  24. 427.6 432.1 m
  25. 288.1 231.9 l
  26. [etc.]
  27. S
  28. [and so on]
  29.  
  30. The guts of my script are:
  31. while (<STDIN>){
  32.   if (/^s/) {print "S\n"; next;}
  33.   tr/u//d;
  34.   ($x, $y, $mode) = split(' ');
  35.   chop($mode);
  36.   $x = $x * 72;
  37.   $y = $y * 72;
  38.   printf "%6.1f %6.1f $s\n", $x, $y, $mode;
  39. }
  40.  
  41. But this takes almost a minute on an 8K line file. From some testing its clear
  42. the split and the printf are the worst time hogs. I want the effects of the
  43. printf though so I only get 1 decimal place on the output. 
  44. Anyone got any tricks that will get the time down?
  45.  
  46. R.G. Ball                    |  phone: 908-594-5341
  47. Merck Research Laboratories  |  FAX:   908-594-6645
  48. PO Box 2000, MD:RY80N-18A    |  email: ball@msdrl.com
  49. Rahway, NJ 07065  USA        |    or   ...!uunet!msdrl!ball
  50.  
  51.