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

Hello all,

I just noticed a thing that somehow escaped me for 20+ years of creating perl modules: if I f ex roll a distro on windows for CPAN, then a unix user will get trouble running bin/ files because the first line in the script cause it to fail like this:

/usr/bin/env: ‘perl\r’: No such file or directory

What would be a best practice for someone like myself who wants to roll distros on both linux and win32? Git checkouts files on linux with LF but on windows with CR/LF, which I thought was smart. One idea is to use `git config --global core.eol lf` but I'm unsure if that the best way around it.

Any good advice?
Thanks!

Replies are listed 'Best First'.
Re: CR/LF in bin
by ikegami (Patriarch) on May 09, 2024 at 17:39 UTC

    You shouldn't be using env. You should be using #!/usr/bin/perl which gets rewritten to the correct line by the installer. A script should use the perl that installed it (and thus has the modules it needs), not whichever happens to be first in the search path. Hopefully, the installer is CR-aware, avoiding the entire issue.

      that works thank you... and I don't even need #!/usr/bin/perl, just #!perl is enough actually, and that was working fine. This one script I stumbled on had #!env perl instead, and that didn't work well for some reason. Possibly a bug in the installer, because #!perl is getting translated quite correctly to #!/usr/bin/perl, while #!env perl translated to #!/usr/bin/env perl but newline is not stripped properly
Re: CR/LF in bin
by eyepopslikeamosquito (Archbishop) on May 10, 2024 at 06:06 UTC

    What would be a best practice for someone like myself who wants to roll distros on both linux and win32?

    I was surprised that Writing Solid CPAN Modules doesn't offer any advice to CPAN authors on this topic, so I need to update it.

    I've always assumed that if the text files (e.g. .pl and .pm files) in your uploaded CPAN tarball are Unix LF-terminated, they'll work fine on all modern Perl platforms (including Windows and MacOS). But I couldn't find a definitive reference on this topic ... so if anyone knows of any cool references on this topic, please let us know.

    Update: I've made a minor tweak to the Mechanics of Creating a New CPAN Module section at Writing Solid CPAN Modules, shown below.

    Mechanics of Creating a New CPAN Module

    Start with: Re: What do I use to release a module to CPAN for the first time? by davido.

    Note: if performing point 2 (Generate your distribution framework) from davido's reference by hand (rather than using Module::Starter):

    • Ensure the text files in your distribution are Unix LF-terminated (not Windows CRLF-terminated).
    • If packaging commands, use #!/usr/bin/perl as their first line, which gets rewritten to point to the correct perl by the installer, as noted by ikegami here.

    👁️🍾👍🦟
      Yes if a distro is rolled on unix so no problem on windows, but not vice versa, apparently. I was greatly confused because if one makes a pure-perl module without magic or compilers involved, one can reasonably expect that windows distro-rolling is very smooth. And this problem was very basic, that's why my confusion.

      Anyway you might want to add to your tutorial how to package bin/ scripts, either use #!perl or nothing at all, but not #!something-else or be prepared to be bitten.

      I believe the "toolchain" modules are pretty careful about being able to produce distros on Windows that work everywhere. If one can make an example of that not being true (which isn't the result of pilot error), then say so here.
        Yes here you go: CRLF-0.01.tar.gz

        $ tar xzf CRLF-0.01.tar.gz $ cd CRLF-0.01 $ perl Makefile.PL $ sudo make install $ rehash $ crlf /usr/bin/env: ‘perl\r’: No such file or directory
A reply falls below the community's threshold of quality. You may see it by logging in.