I must be missing something subtle... or just being a nini and not seeing the obvious.
Help would be greatly appreciated, I think I need to dereference correctly the FILEHANDLE in the print function vs the open function. ?
Particulars
ActivePerl Build 616
Perl version : v5.6.0 built for MSWin32-x86-multi-thread
Goal:
Read source file on specific content, create a new file whose name is composed of part a = 'source content' and part b = 'index'. Then print remaining content read from source to a new file, also keep the new file open in order to do other processing based on file name and/or content, then print additional processed info to the new file and finally close the new file. How is the following possible when not using the strict pragma? Yet when using strict pragma, the code fails to work !?!?

Sample code:
use diagnostics; use strict; open (FILE, "c:\\my\\dir\\src.file.txt") || die "failed to open src file"; while (<FILE>){ my $var_a = $_; my $var_b = "_INDEX"; my $var_c = $_; $var_a =~ s/(^[A-Z]{4})(.*)/$1/o; $comb = $var_a . $var_b; open ($comb, "c:\\my\\dest\\dir\\" . $comb . "found.txt") || die "failure to create" . $comb; print $comb $var_c . "content detail for file found\n"; } close FILE; #_## do some other functions that add more information to file. close $comb.
Using the strict pragma, I have found that I need to do some editing to the open function. Yet the print function alludes me.
WORKS: open ('$comb', "c:\\my\\dest\\dir\\" . $comb . "found.txt") Unable to figure out the print function. ERROR: print $comb $var_c . "content detail for file found\n";
ERROR output: Can't use string ("ACFT_INDEX") as a symbol ref while "strict refs"
Trying to correct this error, the symbolic reference, only has lead to may other but very similar errors.
If I use a fixed FILEHANDLE this works when using the strict pragma and this might be acceptable, not finished with the project yet. I just need to understand why it works when not using the strict pragma. Call it curiosity.
Any help figuring out how to correctly do this would be great.
joseph-

In reply to How do you properly use a variable for FILEHANDLE in print vs open by Anonymous Monk

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.