I have created generic text files, scripts, etc. in order to perform quick installs of the software to various subdirectories.

I inserted variables (e.g. account number) in specific locations within each file, and upon running the install script, I want the 'values' of these variables inserted. But, what is happening is that the raw variables are printed without interpretation.

Here is a sample of the code:
~~~~~~~~~~~~~~~~~~~~~~

sub newfile_create { $account_number = "12345"; $master_file = "/usr/local/foo/htdocs/master_file.txt"; open (IN, "$master_file") or die "Couldn't open file: $!"; $new_file_content = join("", <IN>); close (IN); # Note -- the 'master file' contains a variable, $account_number that +needs to be substituted when the file contents are written into the v +ariable, $new_file_content before writing this data into the $new_fil +e_path location (file). $new_file_path = "/usr/local/foo/htdocs/sub/file1.js"; open(IN, ">$new_file_path"); print IN "$new_file_content"; close(IN); return; }

~~~~~~~~~~~~~~~~~~~~~~
How can I get the $account_number var interpreted before writing to the new file?

Thank you.


In reply to How to interpret a variable from a file vs printing the var? by newbie00

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.