Gossamer Forum
Home : General : Perl Programming :

What's the best way to open a large file?

Quote Reply
What's the best way to open a large file?
I need to unzip a 2GB file on my unix server using gunzip.

I need to read each line and print only every other line.

The server is a Dual Xeon Pentium with 2GB of ram.

Is this possible?

Quote Reply
Re: What's the best way to open a large file? In reply to
Do you mind me asking, WHY????

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: What's the best way to open a large file? In reply to
this is a prime example of why slurping is a bad thing.

Code:
my $t = 0;
open(LF, "your.file") or die "error opening file: $!\n";
print ++$t % 2 ? $_ : '' while (<LF>);
close(LF);
this will give you every other line starting with the first.
if you want it to start with the second, put the ++ on the other side of $t.

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: What's the best way to open a large file? In reply to
Holy smokes - 2GB - thats pretty impressive - can I put my site on your server? Smile (joking)

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: What's the best way to open a large file? In reply to
When I try gunzip -d it tells me that the file is too big, however, there is more than enough space on the drive. Any ideas?

Quote Reply
Re: What's the best way to open a large file? In reply to
Probably cos you only have 2GB of RAM, and some of that will be used on the OS (operating system), so you will probably only have about 1.95GB RAM, not really enough to open the fill fully is it? (not sure, just having an educated guess, am i right?) Cool Smile

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: What's the best way to open a large file? In reply to
In Reply To:
Probably cos you only have 2GB of RAM
What on earth are you on about???????

2GIG of RAM is an AWESOME amount!!!

I think you are getting confused between RAM and disk space.


Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: What's the best way to open a large file? In reply to
i'll take a guess that this is a linux box?
linux on 32 bit OSs doesn't support files larger than 2 gigs and because of that gunzip can't handle it.

try using zcat to split it into smaller sections

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: What's the best way to open a large file? In reply to
Oh well...thought i would have it completley wrong...lol...thats why i said it was an educated guess....maybe not so educated as i thought Cool

Andy

webmaster@ace-installer.com
http://www.ace-installer.com