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

Hello,
I am trying to write a small script involving Mail::Sender, and I get the following error message :
"HASH(0x97f5b20)" is not exported by the Mail::Sender module Can't continue after import errors at ./trajet.perl line 12 BEGIN failed--compilation aborted at ./trajet.perl line 12.
I am kinda new to PERL and I don't really get this message... could anyone help me, please ? Thanks a lot :).
The lines of code that seem to be problematic are :
use Mail::Sender {from => 'navette@mat.ensmp.fr', smtp =>'mail.materiaux.ensmp.fr'}; my $sender = new Mail::Sender

Thanks again !!
Hugo

Replies are listed 'Best First'.
Re: erreur : "HASH(0x97f5b20)" is not exported by
by ForgotPasswordAgain (Vicar) on Jun 27, 2007 at 08:15 UTC

    ECARGOCULT

    Perl requires semicolons between (after) statements. In particular, since you haven't put a semicolon after the first line, use is thinking your hashref (HASH(0x97f5b20)) is one of its arguments (read `perldoc -f use`; it takes a LIST of arguments). You want to use that hashref as an argument to new.

Re: erreur : "HASH(0x97f5b20)" is not exported by
by shmem (Chancellor) on Jun 27, 2007 at 08:23 UTC
    The line
    {from => 'navette@mat.ensmp.fr', smtp =>'mail.materiaux.ensmp.fr'};

    constructs an anonymous hash, which should be the argument to new (the object constructor) and not to use. Just switch the second and third line:

    use Mail::Sender ; my $sender = Mail::Sender->new {from => 'navette@mat.ensmp.fr', smtp =>'mail.materiaux.ensmp.fr'} +;

    In the code above, I have also changed the indirect notation (new Mail::Sender) to direct method invocation. Indirect notation is bad practice unless you know what you do (Indirect notation will bite you if e.g. you have a new() function in the current package, or in some included module you inherit from, which is closer to the current package in the inheritance chain.)

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: erreur : "HASH(0x97f5b20)" is not exported by
by ferreira (Chaplain) on Jun 27, 2007 at 11:09 UTC
    Look closer to the synopsis of Mail::Sender (here). It reads as:
    use Mail::Sender; $sender = new Mail::Sender {smtp => 'mail.yourdomain.com', from => 'your@address.com'}; $sender->MailFile({to => 'some@address.com', subject => 'Here is the file', msg => "I'm sending you the list you wanted.", file => 'filename.txt'});

    So the problem is that you are passing to use Mail::Sender the arguments that should go into Mail::Sender->new. When you do that, the import method of Mail::Sender which expected symbols to be imported into the caller package, tries to do that with the stringification of the hash ref you passed. And then

    "HASH(0x97f5b20)" is not exported by the Mail::Sender module...
Re: erreur : "HASH(0x97f5b20)" is not exported by
by Anonymous Monk on Jun 27, 2007 at 08:50 UTC