Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Awk and Perl unique features

by Anonymous Monk
on Apr 16, 2010 at 05:00 UTC ( #835010=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Are there any features in awk, which are not there in Perl? Although there might hundreds in Perl which are not there in awk. In which areas does awk score over Perl?

Comment on Awk and Perl unique features
Re: Awk and Perl unique features
by Your Mother (Canon) on Apr 16, 2010 at 05:25 UTC

    It's 25% easier to type.

Re: Awk and Perl unique features
by Marshall (Prior) on Apr 16, 2010 at 05:41 UTC
    Awk can be shorter in terms of "number of source characters" but it is more obtuse than well written Perl code. For me, that just kills awk vs Perl.
Re: Awk and Perl unique features
by CountZero (Bishop) on Apr 16, 2010 at 06:16 UTC
    Perl being a Turing complete computer language, there is nothing awk does that Perl can't do.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Is awk turing complete? If it is, then your argument holds good and everything that's possible in Perl should also be possible in awk.
      If you Google for "Is awk Turing complete", you get a lot of links to pages that say awk is Turing-complete although I yet have to find a formal proof, but then again, I didn't check all of the 3470 results of that search.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Awk and Perl unique features
by cdarke (Prior) on Apr 16, 2010 at 07:57 UTC
    I shall try to play devil's advocate.

    awk variables have no sigils, so the code appears cleaner - there are downsides to that, for example it cannot support interpolation (same problem with Python).
    It's internal loop when reading text files is faster than using <ARGV>, however there is no significant difference when perl is used with -p (at least, not with the benchmarks I have run).
    Awk's system footprint is smaller, so on overloaded systems it might perform better on simple tasks.

    Having done quite a lot with awk in the past I can only suggest that we thank it for giving Larry the inspiration to write Perl, then move on.
Re: Awk and Perl unique features
by eyepopslikeamosquito (Canon) on Apr 16, 2010 at 09:02 UTC

    From perlvar:

    Remember: the value of $/ is a string, not a regex. awk has to be better for something. :-)
    I suspect this not allowing a regex in Perl's record separtor $/ variable was the source of the famous Larry Wall quote:
    Hey, I had to let awk be better at *something*... :-)

    Seriously, I've used both awk and Perl extensively over the years, and I'd say Perl wins easily for just about everything. Perhaps most tellingly, Perl scales better as programs tend to naturally grow larger over the years (as I similarly argued against Unix shell in Unix shell versus Perl). By all means compare Perl with Ruby and Python, but not awk: it's no contest.

      Larry Wall let awk to be better at *something* in the past, but tsee was not so kind-hearted to awk (fortunately), so he has written File::Stream. :-)
Re: Awk and Perl unique features
by JavaFan (Canon) on Apr 16, 2010 at 09:42 UTC
    Somehow, I find awk '{print $3}' easier to type/remember than perl -anle 'print $F[2]'. That's about the only case I use awk for nowadays - and then I only use it in shell one-liners.

    Of course, if I have to write a program in an environment that doesn't have perl available, I'd use awk. But last time that happened is a few years ago.

      That's why you setup your shell with abbrevs and all you have to type is ,p2 or what not to have it expanded into | perl -lane 'print $F[2]' for you when you hit the space key.

      (OK, technically I have ,2 which expands to | awk '{print $2}' which I use more often out of habit; but I've also got ,pa which expands out to | perl -lane, and thinking it over during the reply I may try making one that expands to | perl -lane 'print $F[~]' where the ~ is where the cursor is left after expansion a la TextMate snippets)

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Re: Awk and Perl unique features
by toolic (Chancellor) on Apr 16, 2010 at 12:45 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://835010]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2014-09-22 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls