News for hackers. Stuff that matters.
Re:The Awk Programming Language (1988) [pdf] by kamaal on Thursday May 24, 2018 @03:56AM (#17141967)
Most 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.

Re:The Awk Programming Language (1988) [pdf] by greenleafjacob on Thursday May 24, 2018 @04:23AM (#17142109)
In 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";
    }
Re:The Awk Programming Language (1988) [pdf] by flukus on Thursday May 24, 2018 @08:45PM (#17149773)
Correct 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.
Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @06:45AM (#17142740)
For 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.

Re:The Awk Programming Language (1988) [pdf] by kamaal on Thursday May 24, 2018 @09:02AM (#17143519)
It 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.

Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @09:37AM (#17143812)
Perl simply isn’t worth it. In all the decades of programming, I’ve yet to run into a problem which could only be solved in Perl because it couldn’t be done in AWK.

And I would hereby like to remind you that every computing problem is fundamentally an input-output problem, and because of this intrinsic property, it is possible to reduce all problems in computing to input-processing-output.

Which is exactly the kind of problem AWK is designed to address.

And AWK doesn’t work with lines, it works on records, for which the fathers of the language cleverly chose the default of ‘\n’, which is reconfigurable.

Re:The Awk Programming Language (1988) [pdf] by textmode on Thursday May 24, 2018 @11:44AM (#17145109)
"In all the decades of programming, I've yet to run into a problem which could only be solved in Perl because it couldn't be done in AWK."

Have you ever pondered the number of projects that, in addition to sh, make and common base utilities, require perl during compilation where awk could have sufficed?

As a single example, have you looked at compiling openssl without perl, using awk instead?

Whenever I see a perl prerequisite I question whether it is truly a requirement or whether other base utilities1 such as awk could replace it.

Assuming it could be removed, how much effort is one willing to expend in order to extinguish a perl dependency?

1. Some OS projects like OpenBSD make perl a base utility.

Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @12:02PM (#17145291)
The illumos project undertook a massive effort to eradicate any and all dependencies on Perl (which had also been made part of the core operating system decades prior, by themselves no less). While they're still at it, they have managed to rip out most of it and replace it with binary executables in C or shell.

Yes, writing a build engine in AWK would be perfectly doable, but the right tool for that job is Make.

Re:The Awk Programming Language (1988) [pdf] by kamaal on Monday May 28, 2018 @02:29AM (#17170875)
That's easy to do.

But that's not the end of it. The whole point of Perl is avoid a salad of C and shell utils. Also in many cases the moment you have to deal with >2 files at a time shell utilities begin to show their limits.

The resulting code is often far more unreadable than anything you will ever write in Perl.

Re:The Awk Programming Language (1988) [pdf] by Annatar on Tuesday May 29, 2018 @05:54AM (#17177772)
I’m sorry you believe that, but it’s simply not true, especially since UNIX is designed to be driven by a combination of binary code and shell executables. Perl is a mess whose syntax borders on hieroglyphic once poured into software. That doesn’t mean that it’s not a capable language; but it’s not a language in which written programs are maintainable or easily debuggable.