Excellent! Thanks Dan
> -----Original Message----- > From: Casey West [mailto:[EMAIL PROTECTED] > Sent: Friday, February 21, 2003 2:50 PM > To: Dan Muey > Cc: Casey West; [EMAIL PROTECTED] > Subject: Re: parsing email from STDIN > > > It was Friday, February 21, 2003 when Dan Muey took the soap > box, saying: > : > : > > : > It was Friday, February 21, 2003 when Dan Muey took the soap > : > box, saying: > : > : Hello list, > : > : > : > : What is the best way to get the headers of an email into a > : > hash and also the text part of the body into an array or variable? > : > > : > Mail::Internet->new() accepts a list reference full of lines > : > in an email message. This is nice, since getting a list from > : > STDIN is not difficult. > : > > : > my $mail = Mail::Internet->new( [ <STDIN> ] ); > : > my $headers = $mail->head->header_hashref; > : > my $subject = $headers->{Subject}; > : > : Thanks again Casey here's what I tried :: > : > : > : #!/usr/bin/perl > : > : use Mail::Internet; > : my $mail = Mail::Internet->new( [ <STDIN> ] ); > : my $headers = $mail->head->header_hashref; > : my $subject = $headers->{Subject}; > : > : print $subject; > : > : OUTPUT > : ARRAY(0x80da1ec) > : > : > : If I change the my $subject line to : > : my @subject = @{${$headers}{'Subject'}}; # or otherwsie do > it in list context it works > : OUTPUT > : mail parse test > : > : I tried doing > : my ($subject) = $headers->{Subject}; > : And other ways of doing it list context all return > : ARRAY(0x80da1ec) > : > : Any ideas?? > > Oh yes, I forgot about this. Email can have multiple headers > of the same name, so this is Mail::Header making sure those > types of headers are not clobbered. You fixed it correctly > above, but if you want an easier approach, this is what I > would go with. > > my $subject = $headers->{Subject}->[0]; > > Casey West > > -- > Corollary to Godwin's Law: > "As a p5p thread grows longer, the probability of a bad pun > approaches one. Once this occurs, that thread is over, and > whoever inflicted the pun is beaten to within an inch of his > life." -- Michael G. Schwern > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]