This is hilarious. A #Google engineer invented #zx to make command line scripting easier with #NodeJS, because at a certain point #shell scripts get too complicated and you need a Real #Programming Language.
This is exactly #Perl’s use case from thirty-six years ago. But the kids want #JavaScript everywhere and would rather it take more work to convert their ascended #Bash scripts to a vastly different syntax.
In a +1 score to #Perl's great back-compatibility, I've had a script called from procmail that's been 100% reliable for the past 15 years maintaining my email, over many years of regular Perl updates.
Watching some of the vids coming out of this year's Perl and Raku Conference. Ingy döt Net's talk on his work on Lingy and YAMLScript was pretty amazing.
Lingy is a #clojure hosted on #perl - Perl code can call Lingy code can call Perl code. The idea of having a Lingy VM with JIT is very appealing.
YAMLScript is a YAML-style dialect of Lingy (or any Clojure implementation), for those who don't like LISP style.
Dear world, I need to hire someone expert in installing & configuring some open-source software on MacOS. Currently my blogging system breaks every time I type "brew upgrade" and I am out of patience. [EDIT: Problem solved.]
Tl;dr: I need to arrange that this 2-line Perl program works and survives updates:
use DBI;
use DBD::mysql;
Will pay an appropriate hourly rate. Private-message or email me.
Me: "hm, there is no curl or wget in this image, and i’m not root, what can i use to download a binary, oh there is /bin/perl, surely downloading something with that should be possible"
I've been trying for 1.5 hours now to figure out how to use a debugger in #Perl and am reminded once again that this entire language is an enormous fucking garbage fire, especially considering documentation.
So, when neither try nor catch are declared, the source:
try {
print "in try";
} catch {
print "in catch";
}
return 42;
is parsed as```
(print "in try")->try((print "in catch")->catch(return 42));
because of the **Indirect Object Syntax** (the thing that makes `my $obj = new Class @args` equivalent to `my $obj = Class->new(@args)`, and also allows `print { $filehandle } @values`)
«but wait!», you’ll say, «why am I not getting `Can't locate object method "try" via package "1"`?» (after all, `print` returns 1, and `sub 1::try` is definitely not there)
and the answer is: the missing semicolon!
see, before looking up a method, perl evaluates all its arguments, in order from left to right. So it first evaluates `print "in try"`, then `print "in catch"`, then `return 42`, at which point the control returns to the caller *and neither `try` nor `catch` are ever looked up*!
Indeed, if you run:```
sub thing {
try {
print "in try";
} catch {
print "in catch";
};
return 42;
}
thing;
(notice the semicolon before return!) you'll get (pardon the newlines):```
in try
in catch
Can't locate object method "catch" via package "1"
and the program dies.
Maybe I should mandate `no indirect` in all our files…
@Perl@chirp.social
Inside a #Perl script I wanted to compare an input string against an array of strings. When the input exactly matches against one of the array items, then print that a match was found.
One way to solve this is to use the Perl-internal grep function (similar in behaviour to the grep Shell command, but not exactly the same).
Twelve years I started with Perl and I still can't remember EVERY TIME which one between ^ and $ should be used to match begin and end of regex pattern 🤔
Any mnemonic or memory aid? I can use a cheat sheet, but come on…
v1.0 then:
“Perl is kind of designed to make #awk and #sed semi-obsolete […] The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).” https://github.com/Perl/perl5/releases/tag/perl-1.0
Count the number of binary bits of difference between two characters in #Perl:
% perl -E 'say scalar @{[ sprintf("%b", ord "D" ^ ord "C") =~ /1/g ]}'
3
Explanation:
1 . ord gets characters' code points
2. ^ XORs them (1 bit for each different bit)
3. sprintf to binary string
4. =~ /1/g matches every 1
5. […] creates array reference so list context captures every match
6. @{…} dereferences to array
7. scalar counts array elements
8. say outputs result
languages that are involved in some sort of data analysis and processing (#sql, #clang /c++) are doing very well. Not sure what to make of #Python; are ppl in #AI seeing through the reality is a scripting over extremely performant c/c++ and that there are other lang that can glue as well? #golang & #Julia are ⬆️
@Perl I have a hard time getting this database query to work with DBIx::Class. I gave my best to describe it in a useful way. I’d very much appreciate any hints or questions: