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

I don't understand why something seemingly so simple turns into rocket science. Please forgive my frustration. Here is my script:
#!/usr/bin/perl -w use strict; use Mail::Message; my $msg=Mail::Message->read(<STDIN>); my @from=$msg->from; print($#from,"\n");
I feed it a randomly selected email source and get this:

Odd number of elements in hash assignment at /usr/lib/perl5/site_perl/5.8.8/Mail/Message/Construct/Read.pm line 17,<STDIN> line 106.
WARNING: Illegal character in field name From - Thu Oct 16
-1

How could I possibly have done anything wrong in this? TIA.

Replies are listed 'Best First'.
Re: Mail::Message Problem
by f00li5h (Chaplain) on Nov 05, 2008 at 00:40 UTC

    Mail::Message wants Mail::Message->read(FILEHANDLE|SCALAR|REF-SCALAR|ARRAY-OF-LINES, OPTIONS)

    you are giving it a list of lines read from the file... since you've got a readline in list context ...

    try ->read(\*STDIN) or ->read([<STDIN>])

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

      Thanks. So much for trusting examples. That did it.

        ^_^

        @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Re: Mail::Message Problem
by kvale (Monsignor) on Nov 05, 2008 at 00:51 UTC
    When trying to debug a problem like this, is best to start with the simple explanations and go from there. One could look at the module source Read.pm, but understanding the code might be a complex task. So I would look at line 106 in your mail file.

    You don't show us this line, but the the error message gives a clue. Mail messages have fields in the header, like From:, To:, Received:, etc. The apparent problem is that the text on line 106, From - Thu Oct 16 16-1 looks like a malformed From: line.

    This may be due to a malformed mail file; the module may have not seen the end of the mail header and went merrily along parsing body lines. Make sure that mail headers are properly terminated and that there is proper termination of mail messages as well.

    -Mark