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

I know this is a super noob question, but cant figure it out. I need this:
$goodtxt = "asterisk -rx \"celliax_sendsms line0/$word[3] \"Good Passw +ord\"\""; system($goodtxt);
to print out this:
asterisk -rx "celliax_sendsms line0/18157185089 \"your vehicle is now +starting\""
Also I did define $word3, the issue is I dont know how to print the \ into the system command. Any Suggestions?

Replies are listed 'Best First'.
Re: How to include \ in a variable?
by desemondo (Hermit) on Jan 28, 2010 at 21:45 UTC
    Every time you interpolate something, the \ characters will get "evaluated" out of the statement or expression (there is probably a better way to say that, but thats the best I can manage this early in the morning...) .

    The qq{} operator allows to you double quote a string without having to use the double quote " character. Thus you don't need to escape those particular characters with \'s.

    Try this:
    $goodtxt = qq{asterisk -rx "celliax_sendsms line0/$word[3] "Good Passw +ord""};


    Update: If you actually want a literal \ in the output, then you'd need to use a double \\ . So you might actually want:
    $goodtxt = qq{asterisk -rx "celliax_sendsms line0/$word[3] \\"Good Pas +sword\\""};
Re: How to include \ in a variable?
by toolic (Bishop) on Jan 28, 2010 at 21:47 UTC
    Back-whack \\, and also use qq (although, it's not required, but should make it a little easier to read):
    $goodtxt = qq(asterisk -rx "celliax_sendsms line0/$word[3] \\"Good Pas +sword\\"");
Re: How to include \ in a variable?
by ikegami (Patriarch) on Jan 28, 2010 at 22:37 UTC
    If you're not on Windows, your best bet is to completely avoid the shell.
    system(asterisk => ( -rx => qq{celliax_sendsms line0/$word[3] "Good Password"}, ));
Re: How to include \ in a variable?
by pileofrogs (Priest) on Jan 28, 2010 at 22:04 UTC

    And you can always use single quotes inside of the double-quoted string, side-stepping the problem.

    $goodtxt = qq(asterisk -rx "celliax_sendsms line0/$word[3] 'Good Passw +ord'");
Re: How to include \ in a variable?
by Anonymous Monk on Jan 28, 2010 at 21:46 UTC
    $goodtxt = qq[asterisk -rx "celliax_sendsms line0/$word[3] \\"Good Pas +sword\\""]; die $goodtxt; __END__
Re: How to include \ in a variable?
by chuckycharms (Initiate) on Jan 28, 2010 at 21:35 UTC
    Sorry, the second print out should read:
    asterisk -rx "celliax_sendsms line0/18157185089 \"Good Passowrd\""