in reply to Troubleshooting question

Perl interpolates $d as a variable because it's inside backquotes. The inner quotes (the doubles in your case) are handled by the shell.

In your case, it seems that either $d or $DB2DBDFT is undefined. Neither seems to be set by your program. I assume $DB2DBDFT is imported from the environment, which leaves $d. Typo? Should that be $db? Or something else?

Replies are listed 'Best First'.
Re^2: Troubleshooting question
by elittle (Initiate) on Mar 23, 2010 at 16:10 UTC
    $DB2DBFT is an evironment variable that is in the env file. $d is a swtich that is used with sed. I saw on another site where they had the switches inside '{switches}', so I tried that format but it still generated the error. Thanks for replying.
      If you don't want any interpolation at all, use a temporary variable:
      # single quotes prevent interpolation my $sed_command = 'sed -e :a -e "$d;N;2,3ba" -e "P;D" /db2/$DB2DBDFT/M +essages/temp.txt'; my $result = `$sed_command`; # passes a literal $d to sed, not the con +tents of the $d perl variable.
      Perl 6 - links to (nearly) everything that is Perl 6.
        That's not going to work either. That code passes a literal $d to the shell. Use:
        my $sed_command = q{sed -e :a -e '$d;N;2,3ba' -e "P;D" /db2/$DB2DBDFT/ +Messages/temp.txt};
        From the rest of the code of the OP, I presume that the environment variable $DB2DBDFT is set, and that passing a literal $DB2DBDFT to the shell does the right thing.
        Just to clarify $d is NOT a perl variable it is a switch operator used by sed, which I believe is a regular exprssion type of command in UNIX/Linux. Also I believe there already is something similar to what you are proposing in the code already:
        $bkp_info = `sed -e :a -e "{$d;N;2,3ba}" -e "{P;D}" /db2/$DB2DBDFT/Mes +sages/temp.txt`;

        I am not sure if there is much difference in having the key word "my" in front of the variable that you have versus not having it. I have changed the backticks to double quotes and I have also tried using the curly braces as well in conjunction with and without backticks and/or double quotes all to no avail.

        I will try your suggestion and let you know the outcome. Thanks for replying. Could this be a bug?