I mean if file is empty then it should add the $address in ppp.txt's first line otherwise go to the while loop
in this case, rewording and expanding Discipulus' example:
my $file = 'C:\ppp.txt';
print "file '$file' ";
if (-e $file) {
print 'exists ';
if (-z $file) {
print 'but is empty';
} else {
print 'and is not empty';
}
} else {
print q!doesn't exist!;
}
print "\n";
you would have to move your code in like this (untested):
my $file = 'C:/ppp.txt';
print "file '$file' ";
if (-e $file) {
print 'exists ';
if (-z $file) {
# print 'but is empty';
my $fh, '>>', $file, or die "Could not open file '$file' for
+appending: $!";
print$fh $address . ' or whatever you want';
close $fh;
} else {
# print 'and is not empty';
... (your "old" open and while loop)
}
} else {
# print q!doesn't exist!;
... (either create it or print error message)
}
print "\n";
|