Hi, I can suggest an algo
1) read a file into an array : file -> @array 2) @array = grep defined, @array (this removes all the blank values from an @array) 3) write array again back to file kind regards, Kuldeep On Mon, Oct 1, 2012 at 2:04 PM, Irfan Sayed <irfan_sayed2...@yahoo.com>wrote: > hi, > > i need to delete all blank lines from the text file > > > wrote following code. however, all the blank lines are not getting > deleted. please suggest > > > open FILE,"+<", 'C:\Users\bvcontrolbuild\Desktop\test.txt'; > > while (<FILE>) > { > chomp; > push (@lines, "$_\n"); > } > close FILE; > > open FILE,">", 'C:\Users\bvcontrolbuild\Desktop\test.txt'; > > foreach (@lines) > { > > if ($_ =~ m/^\n/) > { > print "hi\n"; > $_ =~ s/^\n//; > } > else > { > print FILE "$_\n"; > } > > } > > close FILE; > > > regards >