demichi has asked for the wisdom of the Perl Monks concerning the following question:
I have 2 questions.
1) Avoid warning message
use strict; use warnings; my $logfile = "test.log"; my $log_fh = *LOG_FH; LOG_MSG_OPEN($log_fh,$logfile); ... sub LOG_MSG_OPEN { my $par_fh = $_[0]; open($par_fh,"> $par_filepath") or die ("Can't open $par_filepath: + $!\n"); $par_fh->autoflush(1); }
gives me this error message: Name "main::LOG_FH" used only once: possible typo at...
Is the only way to get rid of the mssage to add
#no warnings 'once';
?
2) Create FILEHANDLE name from a variable
my $logfile = "test.log"; my $log_fh = "LOG_FH"; LOG_MSG_OPEN($log_fh,$logfile); ... sub LOG_MSG_OPEN { my $par_fh = $_[0]; my $par_filepath = $_[1]; my $par_fh_2 = *${par_fh}; open($par_fh_2,"> $par_filepath") or die ("Can't open $par_filepat +h: $!\n"); $par_fh_2->autoflush(1); }
gives me this error message: Can't use string ("LOG_FH") as a symbol ref while "strict refs" in use..
Is it possible to create FILEHANDLEs with a variable
Thanks for help.
Regards, de Michi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Handle questions
by kcott (Archbishop) on Oct 23, 2016 at 14:09 UTC | |
by demichi (Beadle) on Oct 23, 2016 at 15:30 UTC | |
by kcott (Archbishop) on Oct 27, 2016 at 13:20 UTC | |
by demichi (Beadle) on Oct 23, 2016 at 16:25 UTC | |
by hippo (Archbishop) on Oct 23, 2016 at 22:27 UTC | |
by RonW (Parson) on Oct 25, 2016 at 22:45 UTC | |
|
Re: File Handle questions
by stevieb (Canon) on Oct 23, 2016 at 13:00 UTC | |
by demichi (Beadle) on Oct 23, 2016 at 13:07 UTC | |
by stevieb (Canon) on Oct 23, 2016 at 13:59 UTC | |
by demichi (Beadle) on Oct 23, 2016 at 15:52 UTC | |
by fishmonger (Chaplain) on Oct 23, 2016 at 16:09 UTC | |
by stevieb (Canon) on Oct 23, 2016 at 19:56 UTC |