Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a script that needs to send a series of commands to another command line program. So I open a pipe to the other utility and then create a here document so other non-perl programmers can understand and change the commands if need be. For one of the commands, I want to force the string to be equivlent:
my $label = $_ . "Obsolete" . $timestamp;
This works when I concat the strings before the here document. Is there a way to do this inside the here document section? I've tried:
Command -v$_Obsolete$timestamp
But the $_ and Obsolete don't appear because Perl is looking for a scalar named _Obsolete. Thanks!

davorg: changed title to "Interpolation"

Replies are listed 'Best First'.
Re: Forced Variable Intropolation In Here Document
by Masem (Monsignor) on Nov 27, 2001 at 22:59 UTC
    Use ${varname} to isolate (or force) interpolation. In your case, ${_}Obsolete does the trick.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

Re: Forced Variable Intropolation In Here Document
by dws (Chancellor) on Nov 27, 2001 at 23:01 UTC
    But the $_ and Obsolete don't appear because Perl is looking for a scalar named _Obsolete.

    perlman:perldata to the rescue. The workaround you need is the section titled "Scalar value constructors". It looks like:   Command -v${_}Obsolete$timestamp

(tye)Re: Forced Variable Intropolation In Here Document
by tye (Sage) on Nov 27, 2001 at 23:33 UTC

    Oh sure, giving the standard ${_} answer is easy. But it is more fun to use     Command -v$_$,Obsolete$timestamp (and sometimes more readable). (:

            - tye (but my friends call me "Tye")
Re: Forced Variable Intropolation In Here Document
by Dogma (Pilgrim) on Nov 28, 2001 at 00:12 UTC
    comment removed
      Except that the original poster wanted it equivalent to:

      $_ . "Obsolete" . $timestamp

      He doesn't have a variable by the name of $Obsolete. But otherwise, you're correct.

      Quinn Slack
      perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'