in reply to Removing white space from the file
1) (assuming you have very limited disk-space, but enough memory to read in file)
- read the file in, remove spaces in memory then write it back
2) (not enough memory but say 20% margin of temporary disk space)open my $fh, 'uuu.txt'; my @new = map { s/\s+//g; } <$fh>; close $fh; open $fh '>uuu.txt'; print $fh @new; close $fh;
- for each line read in, remove spaces and write to a compressed file, perhaps on /tmp if it has the space.
- uncompress new file over old
- remove compressed file
Although if there is no such resource problem, better say what the reason is!open my $fh, 'uuu.txt'; open my $gh, '| bzip2 -9 -c > /tmp/uuu.txt.bz2'; # or gzip if no bzip2 while (<$fh>) { s/\s+//g; print $gh $_ or suffer(); } close $fh; close $gh or suffer(); system 'bunzip2 -c /tmp/uuu.txt.bz2 > uuu.txt'; unlink '/tmp/uuu.txt.bz2'; sub suffer { warn "$!: /tmp/uuu.txt.bz2\n"; # e.g. $! reports disk full unlink '/tmp/uuu.txt.bz2'; exit 256; }
One world, one people
|
|---|