6 ms·
What I like about AWK is that it is described by a few pages of the POSIX standard. If Perl was that ubiquitous and simple, I would prefer it over AWK.
by kqr 8y ago
What I like about AWK is that it is described by a few pages of the POSIX standard. If Perl was that ubiquitous and simple, I would prefer it over AWK.
- ajross 8y agoTo be clear: I like that about it too. But in the real world, we want tooling that does more stuff. In the mid-90's, "everyone" knew perl, because it was the best choice for problems in this space. And in a world where everyone knows perl, there is no place for awk. But now we live in a world where no one knows perl, and languages like python and javascript are clumsy and weird in this space. And that makes awk look clever and elegant. All I'm saying is that in perl-world (which was a real place!), awk wasn't clever and elegant, it was stale and primitive. And that to me is more surprising than awk's cleverness.
- fiddlerwoaroof 8y agoI think people underestimate the importance of medium-powered tools. Perl is great, but awks limitations make it easier to write in a way that the next person can maintain.
- fiddlerwoaroof 8y agoThat being said, the couple times I’ve paired with a perl wizard were revelatory.
- kqr 8y agoI totally see your point. And in Perl-world, I would probably use Perl too – I mean, if both tools are equally ubiquitous, why not use the most powerful one? I entered the field at the tail end of the Perl era, so I've only toyed with it a long time ago.
- kamaal 8y ago>>And that makes awk look clever and elegant. Eventually the cycle will repeat again. The moment you will have non trivial text work to do, awk will have to give way to Perl. The rise of Python was really use case for dealing with standard interfaces like DBs/XMLs/JSONs becoming common. Python hasn't actually replaced Perl in any meaningful way.
- oblio 8y agoMost modern distributions write their tools in Python instead of Perl. Proof: the really long transition process Fedora (and therefore RHEL), Debian and Ubuntu went through to migrate from Python 2 to 3. They could have done it faster if not for their system tools written in Python 2. In the web space, Python is not huge, but it definitely supplanted the niche Perl used to have. No one I know writes web stuff in Perl anymore.
- mozumder 8y agoI hated perl in the mid-90's, and stuck with grep/awk/sed intead, because it was a little more documented-structured. Meanwhile, if you randomly mashed on your keyboard, it would output a perl script. I jumped to Python as soon as I found out about it in the late 90's, because it was exactly what I was looking for in self-documenting structuring. It was great for creating parsers with state-machines. I was also the user of my scripts, and I didn't want to have to relearn what I coded a year or so earlier. Python let me pick that up, and to a lesser extent, awk. State machine programming was really self-documenting in Python.
- singingfish 8y agoI’m sick of the “perl is line noise” narrative. https://pastebin.com/C9hPS8xR https://pastebin.com/C9hPS8xR
- ams6110 8y ago> in a world where everyone knows perl, there is no place for awk. And yet in 2018, I never think about Perl anymore, but use sed, awk, and grep daily.
- mbubb 8y agoThis is a great point
- tannhaeuser 8y agoThat, and awk programs are almost perfectly portable across awk implementations: nawk, gawk, mawk (can't vouch for busybox-awk as I haven't tested it, though I've heard it's good as well). This is of practical importance for portable scripts, since Debian uses mawk [1], RH ships gawk, and Mac OS uses nawk. [1] mawk has recently received new commits by its original author after a hiatus of 20 years or so; see https://github.com/mikebrennan000 https://github.com/mikebrennan000
- dannas 8y agoHere's a picture of the AWK book next to the Camel book https://twitter.com/heinrichhartman/status/771706433452769280 https://twitter.com/heinrichhartman/status/77170643345276928... "#awk doc shows you how to implement a rel-DB and a compiler. #perl doc talks 20p+ about nested data structures."
- FractalLP 8y agoThat is one thing I like better in Python than in Perl. In Perl, I was having difficulty with nested data structures and then realized this was something I did in Python daily without even knowing it was a thing on a conscious level. Who hasn't made some weird dictionary with its values being lists or tuples or something like that?
- ajross 8y agoThis is exactly backwards to my eyes. Perl's autovivification behavior (assigning through a empty reference to something autocreates the object of the right type) makes nested data much, much cleaner. Who hasn't made some weird dictionary with its values being lists and forgotten to check for and write code to create it when it doesn't exist, and had to fix that later after a runtime crash? In perl that's literally covered by the one-line assignment you used to set the field you parsed. This is why it's sad that everyone's forgotten perl.
- FractalLP 8y agoSorry, but I didn't catch your example. Can you explain a little more? What does Perl do better there?
- kqr 8y agoDefaultdicts to the rescue! But I think it should be an explicit choice. If you only intend to have lists at some keys, and then accidentally mistype a key, it shouldn't (in my opinion) silently create a list, effectively hiding the bug.
- kamaal 8y agoMost of awk's 'advanced and hard to do' use cases in Perl go like open (my $FILEHANDLE, '<', $file) or die "Cannot open $file\n"; while(<FILEHANDLE>) { chomp; #Do you stuff here } close(FILEHANDLE); Also perl can do various other things awk just can't. For example removing something from a file and then talking to a database or a web service, or do other stuff like parse a JSON or XML. Deal with multiple files, or other advanced use cases. Unicode work, advanced regexes etc etc. In fact the whole point of Perl was Larry wall reaching the upper limits of what one could do with awk, sed and other utilities and having to use them all over the place in C. Then realizing there was a use case for a whole new language.
- greenleafjacob 8y agoIn fact the boilerplate you describe is mostly redundant if you use perl -p since perl -p results in your program running with this wrapper: LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }
- flukus 8y agoCorrect me if I'm wrong, but this will only be line based won't it? As far as I can tell there is no equivalent of FS/RS/OFS/ORS that make awk the record (not line) based language it is.
- Annatar 8y agoFor example removing something from a file and then talking to a database or a web service, ... Deal with multiple files, or other advanced use cases. I do exactly this every day with AWK. Solving exactly these kinds of problems features prominently in the AWK programming language book.
- kamaal 8y agoIt goes further. Awk is when you entire use case fits into the category of iterating lines in a file. Perl is that plus more things.