Click here to get back home

Perl read file eat up my memory...

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Perl read file eat up my memory... howa 06-01-2008
Get Chitika Premium
Posted by Jim Gibson on June 2, 2008, 3:08 pm
Please log in for more thread options
In article

> Now, I have a program to read the file line by line:
>
> #!/usr/bin/perl
> use strict;
>
> if ( scalar(@ARGV) == 1 ) {
>
> my $filename = ( $ARGV[0] );
> open(IN_FILE, $filename) or die("Could not open the file.");
>
> my $line;
>
> foreach $line (<IN_FILE>) {
>
> print "Test";
> exit;
>
> }
> close(IN_FILE);
>
> }
>
> Suppose the file will read the first line and exit, however, it was
> halt and eating my memory forever, no output for print "Test" or exit
> at all.

Others told you about using while instead of foreach. In addition, if
you don't get output you expect, you should 1) Add a newline character
to your output, and 2) set standard output for no buffering (some call
it auto-flushing) (see 'perldoc -q flush").

--
Jim Gibson

Posted by howa on June 2, 2008, 10:27 pm
Please log in for more thread options
Hi,

On 6$B7n(B3$BF|(B, $B>e8a(B3$B;~(B08$BJ,(B, Jim Gibson
> Others told you about using while instead of foreach. In addition, if
> you don't get output you expect, you should 1) Add a newline character
> to your output, and 2) set standard output for no buffering (some call
> it auto-flushing) (see 'perldoc -q flush").
>
> --
> Jim Gibson

Yes, it work now.


Thanks.


Similar ThreadsPosted
How to read big XML files using Perl - Memory Problem November 21, 2005, 3:37 pm
Determine read/write status of filehandles connected to memory objects. March 15, 2006, 11:40 pm
Read xml file and write data to a txt file using PERL.... urgent April 17, 2007, 4:17 pm
Perl takes a lot of memory when you just require a file February 15, 2007, 7:56 am
perl open/close file leaks memory?? September 27, 2007, 1:30 am
Help for the perl read file August 2, 2005, 2:48 pm
How to open and read pdf file in Perl. April 28, 2007, 9:51 am
How to read a pdf file using active perl? August 28, 2006, 9:21 am
How to read access database file with perl? November 16, 2004, 12:50 am
How do I read a GZipped UTF-8 file from Perl on Windows? May 29, 2007, 4:24 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap