Use of hash variables in module call - puzzling behaviour

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a piece of code that is to send mail using Mail::Internet from my
Linux server (Perl 5.8.0).  It reads variables - the recipient, the
outbound mail server and so on - from an XML file into a hash.

Using the variables in the hash causes errors in Mail::Internet; using
equivalent variables from a hash created from data in the program does
not cause the same error.  Odder still, the error doesn't occur at all
when I run the same program under ActiveState Perl in Windows.

Can someone help?  Firstly I'm at a loss to understand why this might
be; secondly I've run out of ideas for debugging the thing.

The program below simulates the reading of the XML through the use of
__DATA__; it builds the Mail::Internet structures $header and $mail; it
then executes the smtp send using first a structure built in the program
itself ($G_server) and then the XML-derived structure ($g_server).  The
program even checks that the corresponding elements in $g_server and
$G_server are the same ...

----------- sample program ------------
#! /usr/bin/perl

use strict;
use warnings;

use Mail::Internet;
use Mail::Header;
use XML::Simple;

my @data = <DATA>;
my $xml = XMLin(join (' ',@data));

my %g_server;

$g_server = $xml -> ;
$g_server = $xml -> ;
$g_server = $xml -> ;

my %G_server = (localuser=>'',

my @message = ("Line 1\n","Line 2");

print ( $g_server eq $G_server ?
    "localuser same\n" : "localuser different\n");
print ( $g_server eq $G_server ?
    "adminuser same\n" : "adminuser different\n");
print ( $g_server eq $G_server ?
    "smtpserver same\n" : "smtpserver different\n");

my $header = Mail::Header->new( ["From:$g_server",
        "Subject:Testing"] );

my $mail =  Mail::Internet->new(Header=>$header,Body=>\@message);

my @recipients;

print "Sending with G_server variables\n";
@recipients = $mail->smtpsend(Host=>$G_server,
print "Mail sent to @recipients\n";

print "Sending with g_server variables\n";
@recipients = $mail->smtpsend(Host=>$g_server,
print "Mail sent to @recipients\n";

----------------- output under Linux ----------------
[nfb@neptune nfb]$ ./
localuser same
adminuser same
smtpserver same
Sending with G_server variables
Mail sent to
Sending with g_server variables
Unrecognised line: at blib/lib/Mail/
(autosplit into blib/lib/auto/Mail/Internet/ line 616
---------------- ends ------------------

OK, I'm braced for someone finding a simple typo in my code ...

Re: Use of hash variables in module call - puzzling behaviour

Quoted text here. Click to load it


I can't see anything that is obviously wrong, and it would take me a
little too much effort to test this (as I do not have access to an SMTP
server that does not require SSL).

However, have you tried turning debug on?

@recipients = $mail->smtpsend(
   Host     => $G_server,
   MailFrom => $G_server,
   To       => $G_server,
   Debug    => 1,

I am not sure if that would help.

The actual source of the message seems to (line 122 in
version 1.67).

I have access to a FreeBSD system (Mail::Address v.1.66) where I tried

asu1@recex:~ > cat
use strict;
use warnings;

use Data::Dumper;
use Mail::Address;

print Dumper (Mail::Address->parse('') );


asu1@recex:~ > perl
$VAR1 = bless( [
               ], 'Mail::Address' );
asu1@recex:~ >

Maybe you can try the same script on your Linux system

(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:

Site Timeline