Saurabh Singhvi wrote: > Hi Hello,
> #!/usr/bin/perl > > open(FILE,'file') or die "Couldn't open $!"; > while (1){ > .. > ... > } > } > > This is a sample code i am using to read a file > Now the issue here is that the complete file gets loaded into memory at once > and then the following job of parsing gets done. Is there a way i can just > load a single line one at a time?? Yes there is: open FILE, 'file' or die "Couldn't open 'file' $!"; while ( my $line = <FILE> ) { ... } > Also if the file(text contents) is a compressed file, which can be viewed > with 'less' and catted by 'zcat' and uncompressed by 'uncompress' in linux, > what's the best way to uncompress it on the fly??? You could just use zcat: open FILE, 'zcat file.Z |' or die "Couldn't open 'file' $!"; while ( my $line = <FILE> ) { ... } close FILE or warn $! ? "Error closing zcat pipe: $!" : "Exit status $? from zcat"; Or you could use the Compress::Zlib module. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>