home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 8044 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.3 KB  |  67 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!agate!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!news.lth.se!hasse
  3. From: hasse@dit.lth.se (Hans Lindkvist)
  4. Subject: Re: Out of memory
  5. Message-ID: <1993Jan28.134255.7650@lth.se>
  6. Originator: hasse@dit.lth.se
  7. Sender: news@lth.se
  8. Reply-To: hasse@dit.lth.se (Hans Lindkvist)
  9. Organization: Dept of Computer Engineering, Lund University, Sweden.
  10. References:  <TSHIONO.93Jan28205613@cxn21.cv.sony.co.jp>
  11. Distribution: comp
  12. Date: Thu, 28 Jan 1993 13:42:55 GMT
  13. Lines: 52
  14.  
  15.  
  16. In article <TSHIONO.93Jan28205613@cxn21.cv.sony.co.jp>, tshiono@cv.sony.co.jp (Toru SHIONO) writes:
  17. |> 
  18. |>     I'm trying to process a very huge (1,000,000 lines) file with
  19. |> a simple Perl script.
  20. |> The processing is done line by line and it doesn't have to keep
  21. |> previous lines; so I presume that it will work no matter how the file
  22. |> may be big.
  23. |> 
  24. |> However, Perl complains "Out of memory!"
  25. |> 
  26. |> To extract the problem, I tested these scripts:
  27. |> 
  28. |>     #!/usr/bin/perl
  29. |>     foreach (1 .. 1000000) {
  30. |>         $line = <>;
  31. |>         print $line;
  32. |>     }
  33. |> 
  34. |> dies shortly, whereas
  35. |> 
  36. |>     #!/usr/bin/perl
  37. |>     for ($i = 0; $i < 1000000; $i++) {
  38. |>         $line = <>;
  39. |>         print $line;
  40. |>     }
  41. |> 
  42. |> works fine !
  43. |> 
  44. |> What makes the difference ?
  45. |> I am afraid that the former loop seems to cause memory leak or
  46. |> something like that.
  47. |> 
  48. |> Any suggestions ?
  49. |> --
  50. |> Toru Shiono (tshiono@cv.sony.co.jp)     Sony Corporation, JAPAN
  51.  
  52. In your first example, following the "foreach" statement, there is a list
  53. (1 .. 1000000). I guess that this list is created with all it's elements
  54. before its processed. In this case you are not even using the elements.
  55.  
  56. -- 
  57. Hans Lindkvist                      Tel: int'l:  +46 46 109763
  58. Dept. of Computer Engineering       Tel: local:     046 109763
  59. Lund University                     Fax: int'l:  +46 46 104714
  60. P.O. Box 118                        Fax: local:     046 104714
  61. S-221 00  Lund, Sweden              Email:  hasse@dit.lth.se
  62. -- 
  63. Hans Lindkvist                      Tel: int'l:  +46 46 109763
  64. Dept. of Computer Engineering       Tel: local:     046 109763
  65. Lund University                     Fax: int'l:  +46 46 104714
  66. P.O. Box 118                        Fax: local:     046 104714
  67.