3 ms·
Many people consider Perl to be the next evolution of awk, but I prefer to think of awk as (just) the essentials of Perl. Perl has CPAN, etc., but for quick str
by silentbicycle 16y ago
Many people consider Perl to be the next evolution of awk, but I prefer to think of awk as (just) the essentials of Perl. Perl has CPAN, etc., but for quick string hackery, everything you need fits in one tiny awk reference. Its design hasn't sprawled the way Perl's has. (Except for gawk. The FSF does bloat better than anyone.)
It's incredibly handy, yet the language is small enough that you can learn most of it in an evening, with just a bit longer if you don't know regular expressions.
- _delirium 16y agoI definitely prefer awk versus perl for one-liners, with some sed thrown in. Perl does have some command-line switches to ease certain kinds of one-liners, but it just feels more verbose for that kind of interactive use (feels more oriented towards writing scripts). I do tend to use Perl for things where speed matters, though, especially with large amounts of data going through a regex--- Perl's regex engine seems considerably faster than any awk (or especially sed) I've tested, at least on a few examples I've ported in the past. I was surprised once to get an 8x speedup by porting a 3-line sed script to a 3-line perl script (it was basically doing s/ABC/A\nC/g on a multigigabyte file). I've heard mawk can be speed-competitive with Perl, though.
- silentbicycle 16y agoSame here, but I prefer Lua to Perl, and Lua's LPEG (http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html) compares very favorably to common regexp implementations. (There are benchmarks in the paper.) It's based on PEGs, a different formalism than regular expressions. PEGs are more expressive - they're able to handle balanced, recursive structures, for example. LPEG is a nice middle ground between regular expressions and a full LALR(1) parser.
- swift 16y agoI'm not sure if "middle ground" is quite right; PEGs and CFGs can express a different set of languages, and each has their own advantages. Probably the most important tradeoff is that with PEGs you gain infinite lookahead and negation, but you lose left recursion and the ability to express ambiguity.
- silentbicycle 16y agoI meant "middle ground" in a practical sense, rather than the linguistic one - REs are good for simple string hackery, but not sufficient for nested structures. Using an actual parser generator (the yacc clone in your language of choice) can really be overkill for simple things, though. LPEG is a bit more expressive than just REs, but still easy to casually drop in during quick scripting.