in reply to A problem with variables inside a system() call

No, perl should wait for the command to finish before it returns, and even if it didn't should build the entire shell command before executing it. Is this a multithreaded program? Can you give a snippet that actually reproduces the problem? I tried something simple like this:

$threshold=25; foreach $variable (23..30) { if ($variable < $threshold) { $command = '/bin/cat'; $UPDATE = `$command << EOF $variable is the value from DB. $variable is less than $threshold EOF`; print "Update: '$UPDATE'\n"; } }
and it worked as expected.

Replies are listed 'Best First'.
Re: Re: A problem with variables inside a system() call
by sagat (Novice) on May 13, 2004 at 22:23 UTC
    Hi:

    Ok, Im beginning to think this might be a problem with the command itself. I just added a print " "; around the $UPDATE section to the EOF piece, and the output looks exactly as it should.

    The program should be singlethreaded, although the perl itself was compiled as multithreaded.

    BTW, the $command was actually a propriatary sql interface to some strange DB.

    BTW, I was looking at the thread of answers behind my question and Davido was refering to a "HERE doc." I've never heard of that before....
    -chris

      << introduces a here document. The syntax and name come from the shell; < filename means get the input from a filename, and << means get the input from right here.

      You can find more in the perldata(1) manpage, or the manual for your shell.

        Thanks for the info.

        In any case, I got the $command << EOF from some other perl code provided by the DB maker, and I never felt quite comfortable with it. I guess it works, but I think I'll redo it using system().

        Once again, thanks for the help!

        -chris