in reply to Speed comparison between printing to STDOUT and printing to a filehandle
I don't know which will be faster, I very strongly suspect that there will be no difference at all between them. As previously mentioned, though, the only way to tell for sure would be to use the Benchmark module.
With your second example, though, once you close the FILE filehandle, you will also have a closed STDOUT - which means that you will no longer see anything printed to STDOUT.
You can get around this with the "local" operator, though. Something like this:-
print "Hello World!\n"; { open (FILE, ">bob.txt"); local *STDOUT = *FILE; print "this is text\n"; close FILE; print "You will never see this\n"; } print "You will see this though\n";
|
|---|