Hi all

thanks for the reply.

The gzip and zcat ones seem like what i was looking for.

But about the reading part:

I was using the same way for reading. I thought that was the standard way.
But the thing is even though i am readin the file line by line, the file is
loaded
completely to the memory while i am opening it with the handle. I was using
the
below program to change some lines in an sql file:

#!/usr/bin/perl

open(SQL,'ibf_dbbackup.sql') or die "Couldn't open $!";
open(OUT,'>out.sql') or die "Couldn't open $!";
while ($record = <SQL>){
        if ($record =~ /DEFAULT CHARSET\=latin1/) {
                $record =~ s/DEFAULT CHARSET\=latin1//;
                print OUT "$record";
        }
        else {
                print OUT "$record";
        }
}


The file was 95mb big, so it immediately occupied around that much amount of
swap
(since memory wansn't free). Now i don't want that to happen, if it can be
helped.

So kindly tell me how to go about it.

Thanks
Saurabh

On 3/7/06, John W. Krahn <[EMAIL PROTECTED]> wrote:
>
> 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>
>
>
>

Reply via email to