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

hello. I am new to perl and was testing a email module from sample section as below but hitting a wall with the error. I don't know what it means in english.
#!/usr/bin/perl use strict; use warnings; # first, create your message use Email::MIME; my $message = Email::MIME->create( header_str => [ From => 'you@example.com', To => 'joshipv2@gmail.com', Subject => 'Happy birthday!', ], attributes => { encoding => 'quoted-printable', charset => 'ISO-8859-1', }, body_str => "Happy birthday to you!\n", ); # send the message1 use Email::Sender::Simple qw(sendmail); sendmail($message);
Jesses-MacBook-Pro:perl jessep$ ./sendemail.pl Can't locate Email/MIME.pm in @INC (@INC contains: /Library/Perl/5.16/ +darwin-thread-multi-2level /Library/Perl/5.16 /Network/Library/Perl/5 +.16/darwin-thread-multi-2level /Network/Library/Perl/5.16 /Library/Pe +rl/Updates/5.16.2 /System/Library/Perl/5.16/darwin-thread-multi-2leve +l /System/Library/Perl/5.16 /System/Library/Perl/Extras/5.16/darwin-t +hread-multi-2level /System/Library/Perl/Extras/5.16 .) at ./sendemail +.pl line 6. BEGIN failed--compilation aborted at ./sendemail.pl line 6. Jesses-MacBook-Pro:perl jessep$
please help a fresh newbie :)

Update I have finally figured the issue and solved it. This program is now working. Thank you Ken and everyone!

Replies are listed 'Best First'.
Re: Can't locate Email/MIME.pm in @INC
by kcott (Archbishop) on Mar 21, 2014 at 20:39 UTC

    G'day netperl,

    Welcome to the monastery.

    Apple includes its own customised version of Perl with Mac OS X for its own use. It may change this without notice (as part of a Mac OS X update) which can break your Perl applications. If you change it, then you can break how Mac OS X operates. It's best to completely leave it alone and install a version of Perl for your own use: perlbrew is a good option for this (see App::perlbrew for installation and perlbrew for usage).

    Email::MIME is a CPAN module which you'll need to install (using your own Perl version). There's several ways to do this; I use the cpan utility like this:

    $ cpan cpan[1]> install Email::MIME

    -- Ken

Re: Can't locate Email/MIME.pm in @INC
by tangent (Parson) on Mar 21, 2014 at 20:49 UTC
    As Ken points out Email::Mime is not included with the standard version of Perl and I too would advise using perlbrew to set up your own environment. However if you just want to try out sending an email you could use either Mail::Mailer or Net::SMTP which should already be installed - just put use Mail::Mailer; or use Net::SMTP; at the top of your script and then run it to find out - if you don't get an error then you have them available.
      installed perl5 using perlbrew and installed Email using clan as Ken had advised..still getting the same error about @INC I also tried use Mail::Mailer and use Net::SMTP at the top, no dice... How do I make sure where is the version of perl what I just installed? I mean does it put it in a sep. env. automatically?
        I also tried use Mail::Mailer and use Net::SMTP at the top, no dice
        In what way did it fail - can you show the script you used and the error.

        To find the perlbrew perl open up Terminal and type in:

        echo $PERLBREW_PATH Sample output: /Users/user/perl5/perlbrew/bin:/Users/user/perl5/perlbrew/perls/perl-5 +.14.1/bin
        There may be another way to do this but using that output you would have the first line of your script:
        #!/Users/user/perl5/perlbrew/perls/perl-5.14.1/bin/perl5.14.1
        "installed perl5 using perlbrew and installed Email using clan as Ken had advised."

        Did you use the "perlbrew switch ..." command shown in the App::perlbrew documentation I linked to in my earlier reply?

        You'll see "perl -v" after most of those "perlbrew switch ..." commands: this will tell you the current version of Perl that you're using. As I mentioned earlier, "Apple includes its own customised version of Perl": the "perl -v" output will probably indicate the version has been patched if you're still using the System Perl. Here's what I get when running that for the current version (i.e. perl) and the System Perl (i.e. /usr/bin/perl):

        $ perl -v This is perl 5, version 18, subversion 1 (v5.18.1) built for darwin-th +read-multi-2level ...
        $ /usr/bin/perl -v This is perl 5, version 12, subversion 3 (v5.12.3) built for darwin-th +read-multi-2level (with 2 registered patches, see perl -V for more detail) ...
        "still getting the same error about @INC"

        The "/Library/Perl/..." and "/System/Library/Perl/..." paths in @INC indicate the System Perl. If you are getting the same output, then you're still using the System Perl.

        However, while that could indicate you haven't done "perlbrew switch ..." yet (or correctly), it's probably more likely to be related to your shebang line. [If you're still having problems (after all of this), advise us exactly how you're running your script: that may pinpoint the problem (if it still exists).]

        I use the following shebang line for all of my Perl scripts:

        #!/usr/bin/env perl

        You can add options after that if you want (see perlrun). A common one you'll see in my posts is:

        #!/usr/bin/env perl -l
        "How do I make sure where is the version of perl what I just installed?"

        "which perl" (from the command line) will tell you this. If it reports /usr/bin/perl, you're still using the System Perl: refer back to my earlier comments about "perlbrew switch ...".

        -- Ken