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

In my quest for laziness I am trying to acquire habits which make my code modular such as making the bits that may uh vary into variables.
When I altered this code:
open MAIL,'|mail mena@uranus.com' || die "mail problem : $!"; print MAIL "$user changed the menu $words.\n"; close MAIL;

like so:
open MAIL,'|mail $mail' || die "mail problem : $!"; print MAIL "$user changed the menu $words.\n"; close MAIL;

and declared $mail like so at the beginning of script: my $mail ='menu@uranus.com';

I get Malformed mail headers in my error log. Can someone advise me as to how I might specify the mail addie as a scalar?
TIA
jg

Replies are listed 'Best First'.
Re: Malformed Headers due to using scalar for address
by Chmrr (Vicar) on Sep 21, 2001 at 07:37 UTC

    Two problems:

    • Single quotes don't interpolate variables. Make that "|mail $mail" for starters..
    • Secondly, you're using || instead of or. || binds much tighter than or, causing your line to be parsed as follows:
      open MAIL, ("|mail $mail" || die "mail problem: $!");
      ..which is probably not what you want. Make it:
      open MAIL, "|mail $mail" or die "Mail problem: $!";
      to make it do the Right Thing.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^+*`^ ve^#$&V"+@( NO CARRIER'

Re: Malformed Headers due to using scalar for address
by earthboundmisfit (Chaplain) on Sep 21, 2001 at 07:32 UTC
    Did you mean to single quote the variable?
    open (MAIL,"|mail $mail") || die "mail problem : $!";
    

    update: added parens per Chmrr's point below
Re: Malformed Headers due to using scalar for address
by jlongino (Parson) on Sep 21, 2001 at 07:33 UTC
    I think you want "|mail $mail", not '|mail $mail'. The single quotes do not interpolate the data value, but the double quotes do.
    @a=split??,'just lose the ego and get involved!';
    for(split??,'afqtw{|~'){print $a[ord($_)-97]}
Re: Malformed Headers due to using scalar for address
by mandog (Curate) on Sep 21, 2001 at 09:43 UTC
    You might also check out

    perldoc -m net::smtp
    This has the advantage on not requiring you to run on a machine with the "mail" program in your path.



    --mandog