Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Superior methods exist for what you want to do (see other posts and the caveat at the end of this one), but the fix for what you have is simple. You need perl to consider your $input as a string to get it to interpolate. This code should work for you:
use strict; my $v1="user_value1"; open(INFILE,"<template.file") or die "Couldn't open file: $!"; my $input=<INFILE>; close(INFILE); $input = '"' . $input . '"';; my $line = eval $input; print "$line\n";
Depending on your desired output, you might also want to chomp off the newline that comes with $input

Also, be exceedingly careful with how you use this. You typically shouldn't eval anything passed from the user, as you're possibly introducing an enormous security headache. String eval on user data is frequently an open invitation for the user to execute code of their choice. I'd sleep easier at night using the s/// operator to fill in the values if that's an option. If you can't do that for whatever reason, use taint checking and thoroughly consider how your script could be abused.


In reply to Re: "eval" variable in non-perl statment? by athomason
in thread "eval" variable in non-perl statment? by ftforger

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (18)
    As of 2014-04-17 14:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (449 votes), past polls