1. 26

Inspired by this discussion

    1. 6

      I like Perl too. (As an aside, I recommend not using GitHub to host code blocks. They render in a huge font size on iPhone and are broken in reader mode.)

      1. 2

        Thanks for the feedback! I’ve replaced them with regular code blocks.

    2. 4

      Very high percentage of my Perl programs has: while(<>)

      That’s something I often miss in other languages. It is so quick and easy way to get both stdin and file support.

      1. 3

        Where do you miss it? Python has fileinput, Ruby has ARGF, are there some usual suspects where it’s not a one-liner?

        1. 1

          Of course, mostly a short comings of me as I never remember and need to fall back on Google every time 😆.

          For Go (for many reasons) it not as simple, but I would like it to be. To be able to quickly write some oneliners with piping programs, ad that is what I mostly do with Perl.

      2. 2

        And yes, I too still use Perl for quick and dirty analysis of logs and what not.

    3. 2

      This reminds I have to clean up and re-publish my awk analytics scripts https://adi.tilde.institute/cbl/.


      You can see users coming from Lobsters and clicking the “READ THE FULL DOCS” button:

      $ ~ grep 14/Sep/2021 /var/www/logs/mkws.shaccess.log | flvr | sort -nrk 2
      "" 67
      "https://lobste.rs/s/8fzzmz/what_are_you_doing_this_week" 26
      "https://mkws.sh/" 22
      "https://mkws.sh/docs.html" 8
      "https://mkws.sh/pp.html" 4
      "https://lobste.rs/" 3
      "https://lobste.rs/comments" 1
      $ ~ grep 14/Sep/2021 /var/www/logs/mkws.shaccess.log | flvp
      /contact.html 1
      /lts.html 9
      /docs.html 25
      /pp/ 1
      /pp.html 10
      / 85
    4. 1

      Installing dependencies is pain.

      1. 1

        I just did this on a freshly-installed perl 5.34.0. What did you try?

        $ cpan Regexp::Log::Common DateTime::Format::HTTP Number::Format

        It took a while, but I’m on a slow VPS.

        This went faster and made less noise:

        $ cpan App::cpanminus
        $ cpanm Regexp::Log::Common DateTime::Format::HTTP Number::Format
        1. 4

          I’ve taken to doing a thing for publicly-available Perl utilities in which

          1. I declare deps in a cpanfile
          2. I submodule cpm into my repo
          3. I include a script that uses cpm to install into ./local and then kicks off a fatpack.
          4. I regenerate and commit the fatpacked script whenever I merge a branch

          This lets people use the thing without installing any deps, but also provides a low barrier to entry to people who want to contribute (they don’t need to use all of my dev tooling, don’t need to use Carton, and don’t even need to find their own decent CPAN client).

          I’ve been meaning to make the script from #3 into something generalized and redistributable, but… not enough time.

          1. 1

            The point of the post was to describe the code for edification, not to distribute it as an installable package.

            1. 2

              Sure, that’s fine. Sorry, just sharing, not trying to push you into doing anything :)

        2. 1

          It was a general complain. I see that people are rediscovering awk and I thought that perl could be the next thing they will use. But after seeing your example it occurred to me that will likely not happen because of tooling. In awk you write a simple, fire and forget script. If you decide you want to write the same script in perl you would use some modules. But on order to do so you need to run your code to see what’s missing. Then install cpanm (you need to know that it exists and why you want to use it) with cpan. Then manually enter required modules name, go for a walk and hope for the best. I know there are/were projects like carton, perl brew, cpanfile but what I want is to be able to write my code and just run it without all the effort needed to set up my environment. It makes writing scripts in perl too much work and there are better languages to write my apps with.

          1. 6

            Perl is a superset of awk: see a2p(1p) ​(a core Perl script).

            You don’t need to use external modules to use Perl scripts. The core has a bunch. OP elected to use a module for web log parsing because it was available, not because it was the only way.

            All succesful languages rely on modules and libraries. Distributing these is an age-old problem. Perl has one solution, which may seem old fashioned, but at least for me, it’s way easier to understand that Python’s (or containers, for that matter).

            Edit in my experience, a lot of *nix software managers include the most popular Perl modules as native “units”. Off the top of my head, this includes Debian/Ubuntu and Free- and OpenBSD.