Search code examples
htmlperlfile-conversioneml

Perl: Can't use 'defined(%hash)'


On MacOS 10.13.6 High Sierra, I want to convert a list of mails that I have exported in eml format files (with Thunderbird), to HTML files.

To perform this, I have installed the tool called "mhonarc".

But at the execution, when I do :

mhonarc -outdir /Users/peter/Mails_HTML /Users/peter/Mails

I get the following error :

Can't use 'defined(%hash)' (Maybe you should just omit the   defined()?) at /opt/local/lib/perl5/vendor_perl/5.28/darwin-thread-multi-2level/mhamain.pl line 1565.
Compilation failed in require at /opt/local/bin/mhonarc line 39.

I don't know if I have the right Perl version. I have installed perl5.26 and perl5.28 via macports and the 3 following macports packages :

p5-mhonarc @2.6.19 (perl)
MHonArc - mail and news munging

p5.26-mhonarc @2.6.19 (perl)
MHonArc - mail and news munging

p5.28-mhonarc @2.6.19 (perl)
MHonArc - mail and news munging

after having done : sudo port searc mhonarc

I think there are conflicts between the native Perl of High Sierra and the Perl package installed with macports but I am not sure.

Edit 1

If I do which perl, I get : /opt/local/bin/perl, so I infer that I am using a version installed from macports.

Here the versions installed and potentially used by mhonarc :

$ /opt/local/bin/perl --version

This is perl 5, version 26, subversion 3 (v5.26.3) built for darwin-  thread-multi-2level

Copyright 1987-2018, Larry Wall

and

$ /usr/bin/perl --version

This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2013, Larry Wall

Edit 2

I followed suggestion done by @choroba: I replaced all all defined(%variable_name) by just %variable_name

So the command mhonarc -outdir /Users/peter/Mails_HTML /Users/peter/Mails doesn't produce error but the issue now is that doesn't produce any mail under HTML format in the directory /Users/peter/Mails_HTML

I get the following output:

This is MHonArc v2.6.19, Perl 5.028002 darwin
Converting messages to /Users/peter/Mails_HTML/
Reading /Users/peter/Mails 

Writing mail 
Writing /Users/peter/Mails_HTML//maillist.html ...
Writing /Users/peter/Mails_HTML//threads.html ...
Writing database ...
0 total messages

What could be the origin of this behavior ?

Edit 3

Problem finally fixed by the modified command line :

mhonarc -outdir /Users/peter/Mails_HTML /Users/peter/Mails/*

which produces all HTML files in /Users/peter/Mails_HTMLdirectory. there is just the dates of email that are missing, I am going to do research for adding this information.


Solution

  • Perl v5.6.1 deprecated the use of defined on collections, but many things have been deprecated and sat there. Then, far later, the Perl developers started dealing with these deprecations. Perl v5.16 started warning about this, and v5.22 finally made it fatal.

    Fortunately, you have v5.18 installed as /usr/bin/perl (the system perl), so you can use that. However, you need to be careful that you are using v5.18 because the macOS system perl is actually two different versions (try strings on it sometime).

    $ ls /usr/bin/perl5*
    /usr/bin/perl5.18   /usr/bin/perl5.28
    

    By default, I get the earlier one (which supports but warns about defined %hash). This way, the macOS system can use the earlier perl, which they've had a long time to test and stabilize:

    $ /usr/bin/perl -v
    
    This is perl 5, version 18, subversion 4 (v5.18.4) built for darwin-thread-multi-2level
    (with 2 registered patches, see perl -V for more detail)
    

    But, as a user, I can tell perl which version I want:

    $ env VERSIONER_PERL_VERSION=5.28 /usr/bin/perl -v
    
    This is perl 5, version 28, subversion 2 (v5.28.2) built for darwin-thread-multi-2level
    (with 2 registered patches, see perl -V for more detail)
    

    I can also choose one as a default for my user (instead of system) processes:

    $ defaults write com.apple.versioner.perl Version 5.28
    
    $ defaults read com.apple.versioner.perl Version
    5.28
    

    But, also be aware that Apple has committed to not distributing scripting language runtimes. So far they haven't turned this off, but eventually you'll have to figure this out with a perl that you install yourself.