|
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
|