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

As usual, this is about Someone Else's Code. Not in a blamey way, just that it seems to be my thing to trip over odd cases and bring them out for scrutiny by the good monks. Today I was successful in installing a module published by our good monk cavac, the CPAN module Array::Contains to a Gnu/Linux system, then a few minutes later I went to install it to my cygwin perl setup. I get an error that takes some scrunching up of one's eyes to figure out.

Simplest test case is a one-liner:

$ perl '-Mdiagnostics' -le 'print $diagnostics::VERSION' couldn't find diagnostic data in /usr/share/perl5/5.40/pods/perldiag.p +od /usr/share/perl5 /usr/local/lib/perl5/site_perl/5.40/x86_64-cygwin +-threads /usr/local/share/perl5/site_perl/5.40 /usr/lib/perl5/vendor_ +perl/5.40/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.40 /us +r/lib/perl5/5.40/x86_64-cygwin-threads /usr/share/perl5/5.40 -e at /u +sr/share/perl5/5.40/diagnostics.pm line 259, <POD_DIAG> line 718. Compilation failed in require. BEGIN failed--compilation aborted.

The first 10 lines of Array::Contains are:

package Array::Contains; use 5.010_001; use strict; use warnings; use diagnostics; use mro 'c3'; use English; our $VERSION = 2.8; use Carp;

I don't see many modules that use diagnostics so this hasn't come up before for me.

Apr 16, 2025 at 02:05 UTC

A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen —> I.G.Y.
(Slightly modified for inclusiveness)

Replies are listed 'Best First'.
Re: diagnostics pragma throwing a compile-time error in Cygwin-Perl
by choroba (Cardinal) on Apr 16, 2025 at 08:56 UTC
    Can you find the file perldiag.pod anywhere else?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      choroba asked:

      Can you find the file perldiag.pod anywhere else?

      I tried out my shell-fu as follows (yes, admittedly, when it's something shellish that takes me a couple minutes to work out, I like to show off ;-):

      $ perl -e'print $_."\0" for @INC' | find  -files0-from - -type f -name perldiag.pod

      The result is no file found with that name. Thanks for your interest, choroba, and this was a good thing to check. Why that file would be missing? Not a clue, right?

      Apr 16, 2025 at 15:43 UTC
        I meant finding it outside the @INC. Using find / or locate (not sure whether it exists on cygwin, though).

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: diagnostics pragma throwing a compile-time error in Cygwin-Perl
by cavac (Prior) on Apr 16, 2025 at 11:41 UTC

    Hmm, strange. According to the source code log, i'm using "diagnostics" in many of my programs since at least October 2018, which by my reckoning was Perl 5.24. Never seen that one before.

    Could you do me a favor? Since i can't reproduce the error, could you test the following and post the output? Just to make sure that i can update CPAN and make diagnostics optional.

    use 5.010_001; use strict; use warnings; use diagnostics; my $diagnosticsenabled; BEGIN { $diagnosticsenabled = 0; eval { use diagnostics; $diagnosticsenabled = 1; }; } if(!$diagnosticsenabled) { print "'use diagnostics' is not available, you will not get detail +ed error messages.\n"; } else { print "diagnostics module loaded!\n"; }

    Until you find a solution, you can safely delete the "diagnostics" line. In fact, you can reduce the whole Contains.pm to:

    package Array::Contains; use 5.010_001; use strict; use warnings; our $VERSION = 2.8; use Carp; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(contains); sub contains { my ($value, $dataset) = @_; if(!defined($value)) { croak('value is not defined in contains()'); } if(!defined($dataset)) { croak('dataset is not defined in contains()'); } if(ref($value) ne '') { croak('value is not a scalar in contains()'); } if(ref($dataset) ne 'ARRAY') { croak('dataset is not an array reference in contains()'); } foreach my $key (@{$dataset}) { next if(ref($key) ne ''); if($value eq $key) { return 1; } } return 0; }

    I mean, technically if you plan to make no errors calling the function, you can strip the whole thing down even further (untested and not recommended):

    package Array::Contains; use 5.010_001; use strict; use warnings; our $VERSION = 2.8; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(contains); sub contains { my ($value, $dataset) = @_; foreach my $key (@{$dataset}) { next if(ref($key) ne ''); if($value eq $key) { return 1; } } return 0; }

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
    Also check out my sisters artwork and my weekly webcomics
      diagnostics should never be used in a module released on CPAN. It has a number of global impacts that users won't expect.

      Could you do me a favor? Since i can't reproduce the error, could you test the following and post the output? Just to make sure that i can update CPAN and make diagnostics optional.

      Sure thing. You are doing me a favor after all. We're collaborating, the best thing to do on PMo. This is what is output:

      $ perl ./testcode-cavac.pl
      couldn't find diagnostic data in /usr/share/perl5/5.40/pods/perldiag.pod /usr/local/lib/perl5/site_perl/5.40/x86_64-cygwin-threads /usr/local/share/perl5/site_perl/5.40 /usr/lib/perl5/vendor_perl/5.40/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.40 /usr/lib/perl5/5.40/x86_64-cygwin-threads /usr/share/perl5/5.40 testcode-cavac.pl at /usr/share/perl5/5.40/diagnostics.pm line 259, <POD_DIAG> line 718.
      Compilation failed in require at testcode-cavac.pl line 10.
      BEGIN failed--compilation aborted at testcode-cavac.pl line 10.

      Same message as with the simplest test case I posted above. BTW, I think you meant to remove line 4, use diagnostics; which comes before the code you added. I tried deleting it but it made no difference.

      If it isn't essential to the functioning of the module, for CygwinPerl I'll do what you recommended which is to not have diagnostics at all.

      Apr 16, 2025 at 16:32 UTC
Re: diagnostics pragma throwing a compile-time error in Cygwin-Perl
by kcott (Archbishop) on Apr 17, 2025 at 19:31 UTC

    G'day Intrepid,

    I'm a long time user of Cygwin for both personal and $work tasks. I currently have (running on Win10):

    ken@titan ~/tmp $ uname -a CYGWIN_NT-10.0-19045 titan 3.6.1-1.x86_64 2025-04-09 11:31 UTC x86_64 +Cygwin

    I update Cygwin weekly which typically takes just a few minutes; updating infrequently can take hours -- obviously, I'd recommend the former. The last update that I did was less than 12 hours ago and there were multiple pages of perl-* packages (this still only took some minutes).

    I never use the system perl (/usr/bin/perl) except for tests such as those that follow; I do use Perlbrew which I heartily recommend.

    I don't know why you quoted -Mdiagnostics. It seems superfluous but maybe you had a reason. I've used quoted and unquoted versions in the examples below.

    I can't reproduce your error. I rarely use the diagnostics pragma but don't recall ever having encountered problems with this.

    Here's my normal and system perls:

    ken@titan ~/tmp $ perl -v | head -2 | tail -1 This is perl 5, version 40, subversion 0 (v5.40.0) built for cygwin-th +read-multi $ which perl /home/ken/perl5/perlbrew/perls/perl-5.40.0/bin/perl $ /usr/bin/perl -v | head -2 | tail -1 This is perl 5, version 40, subversion 2 (v5.40.2) built for x86_64-cy +gwin-threads-multi

    Here's @INC for both:

    ken@titan ~/tmp $ perl -E 'say for @INC' /home/ken/perl5/perlbrew/perls/perl-5.40.0/lib/site_perl/5.40.0/cygwin +-thread-multi /home/ken/perl5/perlbrew/perls/perl-5.40.0/lib/site_perl/5.40.0 /home/ken/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/cygwin-thread-mu +lti /home/ken/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0 $ /usr/bin/perl -E 'say for @INC' /usr/local/lib/perl5/site_perl/5.40/x86_64-cygwin-threads /usr/local/share/perl5/site_perl/5.40 /usr/lib/perl5/vendor_perl/5.40/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.40 /usr/lib/perl5/5.40/x86_64-cygwin-threads /usr/share/perl5/5.40

    Here's examples of your "Simplest test case":

    ken@titan ~/tmp $ perl '-Mdiagnostics' -le 'print $diagnostics::VERSION' 1.40 $ perl -Mdiagnostics -le 'print $diagnostics::VERSION' 1.40 $ /usr/bin/perl '-Mdiagnostics' -le 'print $diagnostics::VERSION' 1.40 $ /usr/bin/perl -Mdiagnostics -le 'print $diagnostics::VERSION' 1.40

    If you're installing modules on the system perl, you may have inadvertently broken something in the past.

    I don't know enough about your system to offer advice beyond update Cygwin and use Perlbrew. Sorry if that's not particularly helpful for this specific problem. Good luck with your troubleshooting.

    — Ken

      kcott wrote:

      I'm a long time user of Cygwin for both personal and $work tasks. I currently have (running on Win10):
      ken@titan ~/tmp
      $ uname -a
      CYGWIN_NT-10.0-19045 titan 3.6.1-1.x86_64 2025-04-09 11:31 UTC x86_64 Cygwin

      I update Cygwin weekly which typically takes just a few minutes; updating infrequently can take hours -- obviously, I'd recommend the former. The last update that I did was less than 12 hours ago and there were multiple pages of perl-* packages (this still only took some minutes).

      I never use the system perl (/usr/bin/perl) except for tests such as those that follow; I do use Perlbrew which I heartily recommend.

      I know perlbrew is very popular, but I have had some problems with using it - specifically the need to use local::lib. As far as I could tell the problem was that my home directory is not /home/somia but rather C:/Users/somia. I set up that way (in the shell initfiles) because I don't like having two home directories; I want easy, automatic cygwin access (without having to change dirs) to what the surrounding Windows system thinks is "home"—%USERPROFILE%, and I don't like having some config files and so on in two different places. I do buy trouble doing things this way, I must admit. BTW this is the first time I've admitted on Perlmonks, what I'm doing with HOME ;-)

      I don't know why you quoted -Mdiagnostics. It seems superfluous but maybe you had a reason. I've used quoted and unquoted versions in the examples below.

      It was a glitch between the keyboard and the chair. I don't know why I did it, just force of habit I suppose. Sometimes I get into a rush trying to compose nodes and writeups for various fora. Please ignore it ;-) – I'll refrain from editing the node now, so that future readers of this thread will see what we're talking about

      I can't reproduce your error. I rarely use the diagnostics pragma but don't recall ever having encountered problems with this.

      As you've seen, the problem was the absence of the perldiag.pod file because I'd never installed the perl_pods package in cygwin setup. Didn't know it was there (I think I did a search for perl-docs or something once long ago).

      Thanks for jumping in on the thread. I always appreciate hearing from another CygwinPerl user.

      Apr 19, 2025 at 18:16 UTC
        "... the need to use local::lib.

        I don't have local::lib installed under Cygwin -- I don't have any need for it. I checked this with a utility, perlmodver, that I wrote to provide info on installed modules -- here's an example:

        ken@titan ~/tmp $ perlmodver local::lib Data::Dumper Data::Dump NOT FOUND: local::lib ---------------------------------------------------------------------- +-- Data::Dumper 2.189 in /home/ken/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/cygwin-thre +ad-multi/Data/Dumper.pm ---------------------------------------------------------------------- +-- Data::Dump 1.25 in /home/ken/perl5/perlbrew/perls/perl-5.40.0/lib/site_perl/5.40.0/D +ata/Dump.pm ---------------------------------------------------------------------- +--

        The code, if you're interested, is in the spoiler. I have copies of this on many platforms and use it frequently.

        I do require local::lib for other platforms that I use for $work; for example, see perl-local-lib, in the list of packages I need to get cpan to work properly, in the fairly recently posted Re: cpan: Terminal does not support AddHistory. [openSUSE].

        "... I don't like having two home directories ..."

        Same here; except I have more than two:

        • C:\Users\ken
        • /home/ken
          aka C:\cygwin64\home\ken
          aka /cygdrive/c/cygwin64/home/ken
        • Plus multiple archives from old machines all containing ken/ directories.

        I don't use Win10 directly that much; however, when I'm downloading something it typically starts by suggesting a location like ken/some/path/ (i.e. chopping off the important part at the start of the pathname). This use to annoy me intensely -- after many years of usage I've become use to this and have stopped letting it bug me.

        My more normal usage is to start a shell. There's no real problem here as it puts me in my Cygwin home directory:

        ken@titan ~ $ pwd /home/ken

        — Ken