in reply to weird problem

This works just fine:
my $file = 'myfile.txt'; my $txt = do { local (@ARGV, $/) = $file; <> }; $txt =~ s/[\r\n]/ /g; $txt =~ s/ /rand() < 0.5 ? q{ } : "\n"/eg; open(my $fh, '>', $file) or die "$0: Can't open $file for write: $!"; print $fh $txt; close $fh;

Replies are listed 'Best First'.
Re^2: weird problem
by Anonymous Monk on Apr 21, 2012 at 08:49 UTC
    doesnt eventually empty the file, but it only works 2-3 times before it will no longer modify the text in the file. to be able to modify the text, when reading the file all lines must be restored (remove empty lines) and then repeat the process of adding newlines in randomly selected spaces.