So there isn't a problem. That has already been solved. But the solution doesn't make sense to me. If someone could please explain how filehandles and subroutines act and interact, I would appreciate it. Here's what happened.
Now if I run one and then two, only sub one will print to sample.txt. If I change the filehandle in two, to FOUTS, there is no problem. If I tell sub two to create a file, instead of using an already created file, it prints normally to the newly created file, even if I reuse the filehandle. How can this behavior be explained?
Code:
sub one{
open (FOUT, ">sample.txt") || die "Cannot open file: $!";
print FOUT "I am a happy file.\n";
}
sub two{
open (FOUT, ">>sample.txt") || die "Cannot open file: $!";
print FOUT "No problems here!\n";
}
Now if I run one and then two, only sub one will print to sample.txt. If I change the filehandle in two, to FOUTS, there is no problem. If I tell sub two to create a file, instead of using an already created file, it prints normally to the newly created file, even if I reuse the filehandle. How can this behavior be explained?