LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl system function syntax (https://www.linuxquestions.org/questions/programming-9/perl-system-function-syntax-159999/)

Crashed_Again 03-19-2004 06:48 PM

Perl system function syntax
 
Hey folks. I'm a noob and I have a very noob question. Feel free to flame me and tell me how easy this one is. I'm trying to perform the system function but I can't get the syntax correct.

Code:

system("emerge -up world | mail -s "RESULTS" $MAIL_ADDRESS");
My problem is with the quotation marks. The mail command requires double quotes around the -s variable("RESULTS") but this seems to be messing up the entire system call.

Thanks in advance.

AltF4 03-19-2004 07:49 PM

You can
a) use backslash to escape the <"> (double quotes) characters
system("emerge -up world | mail -s \"RESULTS\" $MAIL_ADDRESS");

b) use <'> (single quotes)
system("emerge -up world | mail -s 'RESULTS' $MAIL_ADDRESS");

c) use a perl variable containing the subject (including double quotes)
my $SUBJECT = q/"This is the subject of my mail ..."/;
system("emerge -up world | mail -s $SUBJECT $MAIL_ADDRESS");

d) omit the quotes (only in your special case), as "RESULTS" does not contain any
whitespace and should be perfectly ok :-)
system("emerge -up world | mail -s RESULTS $MAIL_ADDRESS");

"There's More Than One Way to Do It" ...

Crashed_Again 03-20-2004 04:00 AM

hehe thanks a lot. After posting this question I remembered something from my php book about using the backslash. I wondered if it worked in perl too. Well as you pointed out it does. Thanks man.


All times are GMT -5. The time now is 03:09 AM.