#!/usr/local/bin/perl
sub trial
{
open (LOGFILE, 'C:\Users\out.txt');
trial();
}
trial();
Please ignore that it will go into an infinite loop.
Will the filehandle LOGFILE
be local or private to the method?
If no, how can I make it private/local?
I'm aware of my . But I don't know how to use it on File Handles.
Those filehandles are global because they are typeglobs. This can lead to very bad surprises sometimes, because you might by accident overwrite such a filehandle that was defined inside of some module you are using.
If you want lexical filehandles, define them with my
like this:
open my $fh, '<', 'C:\Users\out.txt';
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With