I have an application that reads in the lines from a config file that contain UNIX commands, puts the commands in a menu, and runs the command based on the user selection. An example of one of the lines would be something like "echo $user".
# The standard open file, read lines into an array (@lines), close fil +e is completed # Problem $user = $ENV{USER}; foreach $line(@lines) { print "$line\n"; }
The problem is this... When the application is run it outputs 'echo $user' instead of interpolating the value for $user. How would I get the value to be returned? I did implement a workaround by changing '$user' to 'user' in the config file, then running "=~ s/user/$user/g" in the code, and that worked. But I'm sure there's a better way...

In reply to Interpolating variables from a file by Rich36

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.