You have to make a distinction between empty file (size of 0 bytes) and a file full of blanks (tabs and newlines). The latter will have non-zero size.
In your first code the only way to get a zero-size file would be if %chrsize is empty and foreach $chr (keys %chrsize){ does not loop at all. If $chrsize{$chr} is not defined (i.e. $size=undef) or if it is zero (i.e. $size=0), the foreach $index (0..$size) { will still loop once with $index = 0
You second code is much more likely to produce a zero-size file.
BTW, foreach $index (0..3) loops for 0, 1, 2 AND 3
You really need to use strict; use warnings;
In reply to Re: If Condition causes totally blank Output File/Issue in Writing to Output
by bliako
in thread If Condition causes totally blank Output File/Issue in Writing to Output
by hghosh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |