in reply to Removing white space from the file

A lot depends on why you don't want to write to another file, but here are some options:

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

open my $fh, 'uuu.txt'; my @new = map { s/\s+//g; } <$fh>; close $fh; open $fh '>uuu.txt'; print $fh @new; close $fh;
2) (not enough memory but say 20% margin of temporary disk space)

- 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

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; }
Although if there is no such resource problem, better say what the reason is!

One world, one people