Hello friends,

having another appetizer: I am reading lines from file, whose name contains backticks, with exact name e.g.:

filename_`date +%d%m%Y`.log

I am providing it to Perl script on (Bash) command line this way, to avoid early backticks execution - I don't want shell to execute them, but Perl, later:

script.pl '"filename_`date +%d%m%Y`.log"'

Note the two levels of quotes - single and double - I don't insist on doing it this way, it was just the first successful try how to force Perl not cutting filename after date, because followed by space.

I am processing that input in the script this way (shortened):

my @in_files = (); foreach my $input_glob (@ARGV) { print $input_glob; push @in_files, glob("$input_glob"); } # reading and storing lines foreach my $in_file (@in_files) { open (LINES, '<', $in_file); ...

After having read, I want to write contents to another file, but now with those backticks executed/interpolated (with current date for purposes of this example).

my $out_file = "/other/path/$in_file"; # this opens file ... open (LOGFILE, '>>', $out_file); # ... but still without backticks execution/interpolation

My question is maybe more general, than illustrated in example above: is there a way (ideally simple) how to instruct Perl to execute backticked substring of some variable and interpolate it with the execution result?

Thank you.

Richard


In reply to backticks execution "inside" variable (string) by richard.sharpe

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.