Hi,

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


In reply to File Handle questions by demichi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.