App-a2p
view release on metacpan or search on metacpan
lib/App/a2p.pm view on Meta::CPAN
package App::a2p;
$App::a2p::VERSION = '1.013';
use strict;
use warnings;
1;
=head1 NAME
a2p - Awk to Perl translator
=head1 SYNOPSIS
B<a2p> [I<options>] [I<filename>]
=head1 DESCRIPTION
I<A2p> takes an awk script specified on the command line (or from
standard input) and produces a comparable I<perl> script on the
standard output.
=head2 OPTIONS
Options include:
=over 5
=item B<-DE<lt>numberE<gt>>
sets debugging flags.
=item B<-FE<lt>characterE<gt>>
tells a2p that this awk script is always invoked with this B<-F>
switch.
=item B<-nE<lt>fieldlistE<gt>>
specifies the names of the input fields if input does not have to be
split into an array. If you were translating an awk script that
processes the password file, you might say:
a2p -7 -nlogin.password.uid.gid.gcos.shell.home
Any delimiter can be used to separate the field names.
=item B<-E<lt>numberE<gt>>
causes a2p to assume that input will always have that many fields.
=item B<-o>
tells a2p to use old awk behavior. The only current differences are:
=over 5
=item *
Old awk always has a line loop, even if there are no line
actions, whereas new awk does not.
=item *
In old awk, sprintf is extremely greedy about its arguments.
For example, given the statement
print sprintf(some_args), extra_args;
old awk considers I<extra_args> to be arguments to C<sprintf>; new awk
considers them arguments to C<print>.
=back
=back
=head2 "Considerations"
A2p cannot do as good a job translating as a human would, but it
usually does pretty well. There are some areas where you may want to
examine the perl script produced and tweak it some. Here are some of
them, in no particular order.
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 "C<#???>". You should go through and check them. You might
want to run at least once with the B<-w> switch to perl, which will
warn you if you use == where you should have used eq.
Perl does not attempt to emulate the behavior of awk in which
nonexistent array elements spring into existence simply by being
referenced. If somehow you are relying on this mechanism to create
null entries for a subsequent for...in, they won't be there in perl.
If a2p makes a split line that assigns to a list of variables that
( run in 2.093 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )