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

Hi Folks, I'm new to Perl and to PerlMonks, so please bear with me if my question seems stupid:) So I'm trying to get a backtrace of a core file in Solaris (sun4v Solaris 5.10, sparc), but this Perl script doesn't work, though when i tweak it and run it as a shell command it works! The Perl command i'm using inside of my Perl script is
$COREBT = `dbx -c "where;quit" ${SERVICEBIN} /tmp/core.core01.13778205 +52 2>&1`;
The equivalent shell command works just fine and generates a backtrace.
dbx -c "where;quit" $SERVICEBIN /tmp/core.core01.1377820552
Any inputs/comments are greatly appreciated. Thanks a lot.

Replies are listed 'Best First'.
Re: using dbx with perl
by Athanasius (Archbishop) on Sep 07, 2013 at 03:02 UTC

    Hello Perl_Sheep, and welcome to the Monastery!

    Backticks interpolate, so Perl substitutes the value of $SERVICEBIN for the name, and this happens before the command is passed to the shell. You can suppress interpolation in two ways (see perlop):

    $COREBT = `dbx -c "where;quit" \${SERVICEBIN} /tmp/core.core01.1377820 +552 2>&1`; # Add this: ^ # OR $COREBT = qx'dbx -c "where;quit" ${SERVICEBIN} /tmp/core.core01.137782 +0552 2>&1';

    Did you have use strict; at the head of your script? It would alert you to the fact that $SERVICEBIN is being used without first being declared.

    Also, please display your code within <code>...</code> tags as this makes it easier for the monks to read. And please be more specific about the problem you are facing: just saying “this Perl script doesn’t work“ isn’t much for us to go on!

    Hope that helps,

    Update: Removed unneeded backslash from the single-quoted version. Thanks to AnomalousMonk for the heads-up.

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,