home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- 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
- From: hasse@dit.lth.se (Hans Lindkvist)
- Subject: Re: Out of memory
- Message-ID: <1993Jan28.134255.7650@lth.se>
- Originator: hasse@dit.lth.se
- Sender: news@lth.se
- Reply-To: hasse@dit.lth.se (Hans Lindkvist)
- Organization: Dept of Computer Engineering, Lund University, Sweden.
- References: <TSHIONO.93Jan28205613@cxn21.cv.sony.co.jp>
- Distribution: comp
- Date: Thu, 28 Jan 1993 13:42:55 GMT
- Lines: 52
-
-
- In article <TSHIONO.93Jan28205613@cxn21.cv.sony.co.jp>, tshiono@cv.sony.co.jp (Toru SHIONO) writes:
- |>
- |> I'm trying to process a very huge (1,000,000 lines) file with
- |> a simple Perl script.
- |> The processing is done line by line and it doesn't have to keep
- |> previous lines; so I presume that it will work no matter how the file
- |> may be big.
- |>
- |> However, Perl complains "Out of memory!"
- |>
- |> To extract the problem, I tested these scripts:
- |>
- |> #!/usr/bin/perl
- |> foreach (1 .. 1000000) {
- |> $line = <>;
- |> print $line;
- |> }
- |>
- |> dies shortly, whereas
- |>
- |> #!/usr/bin/perl
- |> for ($i = 0; $i < 1000000; $i++) {
- |> $line = <>;
- |> print $line;
- |> }
- |>
- |> works fine !
- |>
- |> What makes the difference ?
- |> I am afraid that the former loop seems to cause memory leak or
- |> something like that.
- |>
- |> Any suggestions ?
- |> --
- |> Toru Shiono (tshiono@cv.sony.co.jp) Sony Corporation, JAPAN
-
- In your first example, following the "foreach" statement, there is a list
- (1 .. 1000000). I guess that this list is created with all it's elements
- before its processed. In this case you are not even using the elements.
-
- --
- Hans Lindkvist Tel: int'l: +46 46 109763
- Dept. of Computer Engineering Tel: local: 046 109763
- Lund University Fax: int'l: +46 46 104714
- P.O. Box 118 Fax: local: 046 104714
- S-221 00 Lund, Sweden Email: hasse@dit.lth.se
- --
- Hans Lindkvist Tel: int'l: +46 46 109763
- Dept. of Computer Engineering Tel: local: 046 109763
- Lund University Fax: int'l: +46 46 104714
- P.O. Box 118 Fax: local: 046 104714
-