in reply to File read and strip
First thing I notice is I didn't notice $i being declared. Stacking up lines like that hides stuff. In this case it's even worse because $i should be declared in a much small scope - the for loop.
Next thing is that generally three prarameter open is prefered and open should always be checked:
open FILE, '<', $file or die "Failed to open $file: $!";
A side issue is:
($i)= grep { m/^#/ } $_;
The best you can hope for from that is $i will be undef if $_ starts with a #. That undef gets pushed into @new however. Probably what you really wanted was something like:
! m/^#/ and push @new, $_ for @array;
However your real issue is the while loop. You've just created FILE. It's empty. How many times it while (<FILE>) going to iterate? That is, how many of the 0 lines available in the newly created file is it going to read?
The while loop is not needed at all. The for loop inside it could be replaced by:
print FILE " \n\n $_ \n\n " for @new;
or remain as it is.
|
|---|