[EMAIL PROTECTED] wrote:
Hi,
Hello,
The script below is suppose to erase off, from a file, all blank lines
including newlines, I wrote the regex is as follows : s/^\s*$//;
however after running the script, a last newline remains.
Can someone explain why the regexp can erase off all newlines in the
file except the last newline.
So how do I construct a regex to erase off all the spaces including new
lines. Is this correct and is this the only way [\n\s\t]+
Thanks
########### start of script#############
##### testing.txt look below ############
use strict;
use warnings;
open (MYDATAS , "<testing.txt") || die $!;
my @datas = <MYDATAS>;
close MYDATAS;
foreach (@datas){
s/^\s*$//;
Your problem is that the line "123\n" does not match the pattern
/^\s*$/. Try it using two substitutions like this:
s/^\s+//;
s/\s+$//;
}
open (WRITEDATAS, ">testing.txt") || die $!;
print WRITEDATAS @datas;
close WRITEDATAS;
############### end of script ###################
############ datas in testing.txt consist of tabs, spaces, newlines
etccc.################
123
########### end of testing.txt ###############
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/