in reply to How to handle the error when we try to read an empty text file in perl

If it was a c++ code then i would have done something like this : open my $fh, '<', 'C:\ppp.txt', or die "Could not open file $!"; if ($fh contains an empty file) { // then add this the $address in the ppp.txt's first line }
This is easy in Perl:
my $file = 'c:\ppp.txt'; if (-e -z $file) { warn "$file exists but is zero sized!\n"; open my $tmp, '>', $file or die "cannot write to $file!\n"; # #write what you need to close $tmp }
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
  • Comment on Re: How to handle the error when we try to read an empty text file in perl
  • Download Code