in reply to Removing white-lines...
Should work. On an unrelated note:$file_data =~ s/\n\n+/\n/gs;
The 'open' command is very prone to failure on UNIX systems for lots of reasons (you don't have access to the file, it's not readable, the file's really a directory, etc...), so getting in the habit of checking it is a plus.# Suggest using scalar filehandles and checking to # see if open succeeded... open( my $my_filehandle, $file ) || next; # possibly: || die "Can't open file: $!"; local $/ = undef; # tell perl not to stop reading at newline my $file_data = <$my_filehandle>; close $my_filehandle; # process $file_data # etc...
should work.$file_data =~ s/\n[\s\n]+/\n/gs;
Although that's technically a line-by-line approach.$ perl -ni -e 'print if /\S/' *.shtml
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing white-lines...
by ikegami (Patriarch) on Apr 07, 2007 at 06:41 UTC |