6 ms·
Honest question: Is Awk worth learning to someone who already knows Perl? Every time I read about Awk, I feel very intrigued, but AFAIK, everything Awk can do,
by krylon 5y ago
Honest question: Is Awk worth learning to someone who already knows Perl?
Every time I read about Awk, I feel very intrigued, but AFAIK, everything Awk can do, Perl can just as well. Is there a compelling reason to learn Awk if you know Perl beyond pure curiosity?
- sigzero 5y agoThat's a tough one. Probably not in the sense "I will replace Perl with AWK" but more in a sense of "I want to learn AWK to learn AWK." It is installed everywhere pretty much so it's nice to know. I keep thinking the same since I know Perl.
- krylon 5y ago> "I want to learn AWK to learn AWK." Well, that's what I meant by "pure curiosity". ;-) Which is a perfectly valid reason to learn a language, of course, possibly the best reason one can have. But I guess when I need a quick and dirty one-shot script, I'll stick to Perl for the time being. It's not officially standard like Awk, but it is available in the default installation of pretty much every open source Unix-like system I use except FreeBSD where it's one of the first packages I install. Hypothetically, Perl is also available on systems that are not very Unix-like, such as OS/400 (or "IBM i" as it is called these days, apparently) or VMS. (Hypothetically in the sense that I have never had direct contact with one of these systems and have no expectation I ever will, sadly. ... Well, maybe I should count myself lucky - either way, I will probably never know for sure.)
- Spooky23 5y agoI love Perl, but it’s starting to fade from use. Awk is still everywhere.
- emmelaich 5y agoPerl is faster and more capable than Awk, and is pretty much a superset. So don't bother as long as Perl is ubiquitous.
- davidgould 5y agoPerl is not generally faster than awk. Obviously there are cases where perl is faster, but for the text smashing that awk is meant for, perl usually much slower, particularly than mawk or recent gawk versions. mawk in particular is shockingly fast.
- spectramax 5y agoEverytime I learn Awk, I forget it. It is an infrequently used tool for me.
- adrian_b 5y agoFor simple tasks, Awk is more concise than Perl. While you can write on one line of Perl anything that you can write in one line of Awk, the Perl line will be longer. So for the simple tasks that you would do from the command line or in a shell script, you can usually save time when writing for Awk. For complex tasks, where you need more complex control than the implicit loop of Awk and you also need to define various extra variables besides those pre-defined, Awk is no longer more concise. Then obviously Perl or other scripting languages become more convenient.
- adrian_b 5y agoTo give a quantitative value to what I mean by "more" concise, I have once written a very simple script to find some hash collisions in some files, both in Awk and in Perl. The Awk variant had 350 bytes, while the identical Perl variant had 450 bytes. The extra length in Perl was due to "$" prefix on all variables, an extra "split()" and an extra "while()", which were not needed in Awk. For slightly simpler versions of those scripts executed as one-liners, the difference in length was even much more in favor of Awk, because Perl needed extra command-line options to execute the script in the command line, while that is the default behavior of Awk.
- wernsey 5y agoI actually came from learned Perl before I learned Awk, and the reason I switched is because Awk is a much smaller language, so I can keep it all in my head. I just about never have to refer to the man page. I also found that I can go for months without writing any Awk and then knock out a quick script without having to relearn anything. I'll concede that there are things for which Awk just isn't powerful enough and perhaps I was never that good with Perl to begin with, so if you're already well versed in Perl YMMV