Do you get the same kind of error if you rewrite your statement?
if($variable < $threshold) { my $command = '/usr/bin/blah'; my $updatestring = << "EOF"; $variable is the value from DB. $variable is less that $threshold EOF my $UPDATE = `$command $updatestring`; } else { ... }
Using this extra variable corrects some issues with your here document and should make the code much more readable.

Does it also fix the error?

I would be intersted in knowing how it's going wrong in the first place... do you have a code example that reproduces the error reliably?

One final thing. In some responses above you suggest you will use system instead. I'm sure you know the difference between using backticks and system, but I thought I should point it out anyway.

system returns $? which you can use to determine success or failure (basically if it's true your command failed). If the command called via system prints to STDOUT then that content will go to the STDOUT of your program. Backticks capture the STDOUT from the command and return that. If you call backticks in a list context each new line of data is returned in each list element. If you call it in scalar context you get a string with embedded newlines.

If you want to give up on backticks but still capture the output of the command then perhaps you might want to use:

open ( COMMAND, " $command $updatestring | ") or die $!; while(<COMMAND>) { .... }

I hope this helps

jarich


In reply to Re: A problem with variables inside a system() call by jarich
in thread A problem with variables inside a system() call by sagat

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.