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

I am facing a weird issue. I have a cgi-perl script to display a web form. After submitting I am emailing the data as an attachment. The code I am using to mail is shown below. strangely the mails are not going if I change the subject to anything else other than "test mail". I am not using modules because of lot of dependencies. Do u have any clue? can this be because the subject "test mail" is cached or something like that

my $subject="test mail"; @command1=("uuencode", "<file path>", "<file>"); @command2=("mailx" ,"-s", "'$subject'","-m", "your\@email.com"); system("@command1 | @command2");

Replies are listed 'Best First'.
Re: email subject issue in mailx
by ikegami (Patriarch) on Jan 12, 2010 at 18:18 UTC
    I don't know why you are having a problem — you didn't even say for which values it fails — but the problem might be avoidable by avoiding the shell. Always a good idea anyway.
    open(my $fr_uuencode, '-|', uuencode => ( $file ) ) or die $!; open(my $to_mailx, '|-', mailx => ( -s => $subject, -m => 'sam@pull.com', ) ) or die $!; print $to_mailx $_ while <$fr_uuencode>;

      Thanks for ur quick response... I tried ur code and faced the error: Can't use an undefined value as filehandle reference at 1.pl line 4. The code I used is:

      #!/tools/sde/frame.sde/bin/perl $subject="I am subject"; $hfile="/aim2/actiview/web/scripts/samweb/perl-lib/mbm/mbm_csv/test1/t +2.csv"; open(my $fr_uuencode, '-|', uuencode => ( $hfile ) ) or die $!; open(my $to_mailx, '|-', mailx => ( -s => '$subject', -m => 'manjunath.bm\@alcatel-lucent.com mbm\@alcatel-lucent.co +m', ) ) or die $!; print $to_mailx $_ while <$fr_uuencode>;
        -s => '$subject',

        Don't know about your "undefined value as filehandle reference" error (Update: actually I do: you seem to have an ancient Perl (pre 5.6.1)), but you likely don't want single quotes around $subject.

        In addition to issues identified by almut,
        'manjunath.bm\@alcatel-lucent.com mbm\@alcatel-lucent.com'
        produces the string
        manjunath.bm\@alcatel-lucent.com mbm\@alcatel-lucent.com
        You want
        'manjunath.bm@alcatel-lucent.com mbm@alcatel-lucent.com'
        or
        "manjunath.bm\@alcatel-lucent.com mbm\@alcatel-lucent.com"