I am surprised to see the a2p utility installed by default in my Linux distribution.

a2p is a command line utility that converts an Awk program from standard input to a perl program that it outputs to standard output.

Why would I ever want to convert an Awk program to a Perl program when I have an Awk interpreter installed?

Why is it that Linux distributions include a2p in their default installations?

closed as primarily opinion-based by jasonwryan, don_crissti, steve, cuonglm, Archemar Nov 8 '15 at 7:39

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Ask the developers/maintainers of whatever distro it is that you are using, it is their call... – jasonwryan Nov 7 '15 at 18:49
  • 3
    Because it's part of perl, and perl is installed by default in Linux. – cuonglm Nov 7 '15 at 18:58
  • 1
    One example use would be where folk find themselves with old legacy awk scripts which need to do something funky for which awk doesn't have functionality. Bring it into the modern age with a2p and hey presto you've got all the magic of perl at your fingertips. – steve Nov 7 '15 at 22:28
  • @don_crissti: Ah yeah, it's part of perl source, but the dev/maintainer of the distro can exclude it. – cuonglm Nov 8 '15 at 3:51

You might want to use these tools to increase the efficiency of perl scripts.

You would want to do this if you had a larger perl program and you wanted to integrate the functionality of an awk script without calling a subprocess. You would call a2p and integrate the generated code into an existing perl script.

There's a similar utility, find2perl which takes a find command line and generates perl code to do the same thing, avoiding the call to a find subprocess.

These are optimization tools for perl scripts.

  1. Why it got installed by default ? : Its upto developer/maintainer of the distro that you are using.

  2. Why would you need a2p

There is an awk idiom of putting int() around a string expression to force numeric interpretation, even though the argument is always integer anyway. This is generally unneeded in perl, but a2p can't tell if the argument is always going to be integer, so it leaves it in. You may wish to remove it.

Perl differentiates numeric comparison from string comparison. Awk has one operator for both that decides at run time which comparison to do. A2p does not try to do a complete job of awk emulation at this point. Instead it guesses which one you want. It's almost always right, but it can be spoofed. All such guesses are marked with the comment "#??? ". You should go through and check them. You might want to run at least once with the -w switch to perl, which will warn you if you use == where you should have used eq.

For more information : A2P

  • To be honest , I copied this from A2P documentation , so all credits to them. – rɑːdʒɑ Nov 7 '15 at 19:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.