LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2004, 06:48 PM   #1
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
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.
 
Old 03-19-2004, 07:49 PM   #2
AltF4
Member
 
Registered: Sep 2002
Location: .at
Distribution: SuSE, Knoppix
Posts: 532

Rep: Reputation: 31
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" ...
 
Old 03-20-2004, 04:00 AM   #3
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Original Poster
Rep: Reputation: 57
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl: can I make the system function timeout? apeekaboo Programming 7 07-24-2007 07:52 AM
what are the Hexadecimal function and ASCII function in Perl Bassam Programming 1 06-03-2004 01:44 AM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM
Shell function syntax error... psyklops Programming 1 09-03-2003 01:55 AM
perl syntax jenny_psion Programming 2 08-13-2003 12:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration