LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl question: how to insert an e-mail address in a script (https://www.linuxquestions.org/questions/programming-9/perl-question-how-to-insert-an-e-mail-address-in-a-script-350565/)

Pastorino 08-06-2005 10:26 AM

Perl question: how to insert an e-mail address in a script
 
I'm using Fedora Core 3, and I'm modifying the LogWatch script below:

open(OUTFILE,"|$Config{'mailer'} $Config{'mailto'}") or die "Can't execute /bin/mail\n";
print OUTFILE "From: LogWatcher\n";

to something like:

open(OUTFILE,"|$Config{'mailer'} $Config{'mailto'}") or die "Can't execute /bin/mail\n";
print OUTFILE "From: LogWatcher <operator@domain.com>\n";


What I'm trying to do is to receive an e-mail where the sender is shown only as "LogWatcher", instead of "LogWatcher@domain.com". And when you double click "LogWatcher", the e-mail operator@domain.com shows up.


The problem is that I'm not a perl developer, and my modification is clearly incorrect. It returns the error:

Possible unintended interpolation of @domain in string at /etc/cron.daily/00-logwatch line 681

Does anyone know how to do it?

Thanks.

btmiller 08-06-2005 11:42 AM

The @ is a special character in Perl Z(designates an array variable). You should escape it by typing \@ instead of @ or just enclose your string in single quotes instead of double (which prevents Perl from trying to interpret variables).

eddiebaby1023 08-07-2005 04:36 AM

Easiest way is to put the whole string in single-quotes so no interpolation is done.

Pastorino 08-08-2005 08:28 AM

Hi btmiller and eddiebaby1023,

The \@ worked like a charm! Thanks a lot.


All times are GMT -5. The time now is 02:14 AM.