$msg->sender bug? Or bad usage?

Adam Augustine <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <[email protected]>
I have a script that catches bounces from a mailing list. Some of the 
bounces are very, very odd which tend to tickle bugs in my code.

The relevant chunks of my code are:

my $msg = Mail::Message->read(\*STDIN);
my @from = ();

print "Before\n";
print "\$#from is: $#from\n";
print "\$from is: $from[0]\n";
print "Scalar: ",scalar(@from),"\n";

@from = $msg->sender;

print "After\n";
print "\$#from is: $#from\n";
print "\$from is: $from[0]\n";
print "Scalar: ",scalar(@from),"\n";

my @from_address_list = ();
if ($#from >= 0) {
         foreach (@from) {
                 push (@from_address_list, $_->address);
         }
}

Here is one of the emails that caused the error:

Received: from msnmail2.uswest.net (msnmail2.uswest.net 
[::ffff:63.226.138.22])
   by hambone.com with esmtp; Sun, 18 Jan 2004 12:03:51 -0700
Received: (qmail 57512 invoked by uid 0); 18 Jan 2004 18:30:44 -0000
Received: from unknown (63.226.138.9)
   by msnmail2.uswest.net with QMQP; 18 Jan 2004 18:30:44 -0000
Delivered-To: [email protected]
To: [email protected]
Subject: Re: Harvesting cilantro
References: <[email protected]>
In-Reply-To: <[email protected]>
Message-ID: <[email protected]>
Date: Sun, 18 Jan 2004 12:03:51 -0700

The email address for [email protected] has changed.  Please send all
future correspondence to [email protected].

And when I run "cat badmail | testscript.pl" , I get:

Before
$#from is: -1
Use of uninitialized value in concatenation (.) or string at 
./testscript.pl line 5, <STDIN> line 1.
$from is:
Scalar: 0
After
$#from is: 0
Use of uninitialized value in concatenation (.) or string at 
./testscript.pl line 11, <STDIN> line 1.
$from is:
Scalar: 1
Can't call method "address" on an undefined value at ./testscript.pl 
line 17, <STDIN> line 1.

My understanding is that if an array is empty then $#array should be -1. 
It seems to me that @from = $msg->sender; seems to be doing something 
very strange to @from, making all values none-existent, but changing the 
index.

Maybe my perl isn't strong enough here, but that seems not right to me.

What am I missing?

Adam Augustine
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.