Inspired by this discussion
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.)
Thanks for the feedback! I’ve replaced them with regular code blocks.
Very high percentage of my Perl programs has:
That’s something I often miss in other languages. It is so quick and easy way to get both stdin and file support.
Where do you miss it? Python has fileinput, Ruby has ARGF, are there some usual suspects where it’s not a one-liner?
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.
And yes, I too still use Perl for quick and dirty analysis of logs and what not.
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
$ ~ grep 14/Sep/2021 /var/www/logs/mkws.shaccess.log | flvp
Installing dependencies is pain.
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
I’ve taken to doing a thing for publicly-available Perl utilities in which
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.
The point of the post was to describe the code for edification, not to distribute it as an installable package.
Sure, that’s fine. Sorry, just sharing, not trying to push you into doing anything :)
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.
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.