perl 2.0 patch 1: removed redundant debugging code in regexp.c
[p5sagit/p5-mst-13.2.git] / x2p / a2p.man
CommitLineData
8d063cd8 1.rn '' }`
378cc40b 2''' $Header: a2p.man,v 2.0 88/06/05 00:15:36 root Exp $
8d063cd8 3'''
4''' $Log: a2p.man,v $
378cc40b 5''' Revision 2.0 88/06/05 00:15:36 root
6''' Baseline version 2.0.
8d063cd8 7'''
8'''
9.de Sh
10.br
11.ne 5
12.PP
13\fB\\$1\fR
14.PP
15..
16.de Sp
17.if t .sp .5v
18.if n .sp
19..
20.de Ip
21.br
22.ie \\n.$>=3 .ne \\$3
23.el .ne 3
24.IP "\\$1" \\$2
25..
26'''
27''' Set up \*(-- to give an unbreakable dash;
28''' string Tr holds user defined translation string.
29''' Bell System Logo is used as a dummy character.
30'''
378cc40b 31.tr \(*W-|\(bv\*(Tr
8d063cd8 32.ie n \{\
378cc40b 33.ds -- \(*W-
34.if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
35.if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
8d063cd8 36.ds L" ""
37.ds R" ""
38.ds L' '
39.ds R' '
40'br\}
41.el\{\
42.ds -- \(em\|
43.tr \*(Tr
44.ds L" ``
45.ds R" ''
46.ds L' `
47.ds R' '
48'br\}
49.TH A2P 1 LOCAL
50.SH NAME
51a2p - Awk to Perl translator
52.SH SYNOPSIS
53.B a2p [options] filename
54.SH DESCRIPTION
55.I A2p
56takes an awk script specified on the command line (or from standard input)
57and produces a comparable
58.I perl
59script on the standard output.
60.Sh "Options"
61Options include:
62.TP 5
63.B \-D<number>
64sets debugging flags.
65.TP 5
66.B \-F<character>
67tells a2p that this awk script is always invoked with this -F switch.
68.TP 5
69.B \-n<fieldlist>
70specifies the names of the input fields if input does not have to be split into
71an array.
72If you were translating an awk script that processes the password file, you
73might say:
74.sp
75 a2p -7 -nlogin.password.uid.gid.gcos.shell.home
76.sp
77Any delimiter will do to separate the field names.
78.TP 5
79.B \-<number>
80causes a2p to assume that input will always have that many fields.
81.Sh "Considerations"
82A2p cannot do as good a job translating as a human would, but it usually
83does pretty well.
84There are some areas where you may want to examine the perl script produced
85and tweak it some.
86Here are some of them, in no particular order.
87.PP
88The split operator in perl always strips off all null fields from the end.
89Awk does NOT do this, if you've set FS.
90If the perl script splits to an array, the field count may not reflect
91what you expect.
92Ordinarily this isn't a problem, since nonexistent array elements have a null
93value, but if you rely on NF in awk, you could be in for trouble.
94Either force the number of fields with \-<number>, or count the number of
95delimiters another way, e.g. with y/:/:/.
96Or add something non-null to the end before you split, and then pop it off
97the resulting array.
98.PP
99There is an awk idiom of putting int() around a string expression to force
100numeric interpretation, even though the argument is always integer anyway.
101This is generally unneeded in perl, but a2p can't tell if the argument
102is always going to be integer, so it leaves it in.
103You may wish to remove it.
104.PP
105Perl differentiates numeric comparison from string comparison.
106Awk has one operator for both that decides at run time which comparison
107to do.
108A2p does not try to do a complete job of awk emulation at this point.
109Instead it guesses which one you want.
110It's almost always right, but it can be spoofed.
111All such guesses are marked with the comment \*(L"#???\*(R".
112You should go through and check them.
113.PP
114Perl does not attempt to emulate the behavior of awk in which nonexistent
115array elements spring into existence simply by being referenced.
116If somehow you are relying on this mechanism to create null entries for
117a subsequent for...in, they won't be there in perl.
118.PP
119If a2p makes a split line that assigns to a list of variables that looks
120like (Fld1, Fld2, Fld3...) you may want
121to rerun a2p using the \-n option mentioned above.
122This will let you name the fields throughout the script.
123If it splits to an array instead, the script is probably referring to the number
124of fields somewhere.
125.PP
126The exit statement in awk doesn't necessarily exit; it goes to the END
127block if there is one.
128Awk scripts that do contortions within the END block to bypass the block under
129such circumstances can be simplified by removing the conditional
130in the END block and just exiting directly from the perl script.
131.PP
132Perl has two kinds of array, numerically-indexed and associative.
133Awk arrays are usually translated to associative arrays, but if you happen
134to know that the index is always going to be numeric you could change
135the {...} to [...].
136Iteration over an associative array is done with each(), but
137iteration over a numeric array is NOT.
138You need a for loop, or while loop with a pop() or shift(), so you might
139need to modify any loop that is iterating over the array in question.
140.PP
141Arrays which have been split into are assumed to be numerically indexed.
142The usual perl idiom for iterating over such arrays is to use pop() or shift()
143and assign the resulting value to a variable inside the conditional of the
144while loop.
145This is destructive to the array, however, so a2p can't assume this is
146reasonable.
147A2p will write a standard for loop with a scratch variable.
148You may wish to change it to a pop() loop for more efficiency, presuming
149you don't want to keep the array around.
150.PP
151Awk starts by assuming OFMT has the value %.6g.
152Perl starts by assuming its equivalent, $#, to have the value %.20g.
153You'll want to set $# explicitly if you use the default value of OFMT.
154.PP
155Near the top of the line loop will be the split operation that is implicit in
156the awk script.
157There are times when you can move this down past some conditionals that
158test the entire record so that the split is not done as often.
159.PP
160There may occasionally be extra parentheses that you can remove.
161.PP
162For aesthetic reasons you may wish to change the array base $[ from 1 back
163to the default of 0, but remember to change all array subscripts AND
164all substr() and index() operations to match.
165.PP
166Cute comments that say "# Here is a workaround because awk is dumb" are not
167translated.
168.PP
169Awk scripts are often embedded in a shell script that pipes stuff into and
170out of awk.
171Often the shell script wrapper can be incorporated into the perl script, since
172perl can start up pipes into and out of itself, and can do other things that
173awk can't do by itself.
174.SH ENVIRONMENT
175A2p uses no environment variables.
176.SH AUTHOR
177Larry Wall <lwall@devvax.Jpl.Nasa.Gov>
178.SH FILES
179.SH SEE ALSO
180perl The perl compiler/interpreter
181.br
182s2p sed to perl translator
183.SH DIAGNOSTICS
184.SH BUGS
185It would be possible to emulate awk's behavior in selecting string versus
186numeric operations at run time by inspection of the operands, but it would
187be gross and inefficient.
188Besides, a2p almost always guesses right.
189.PP
190Storage for the awk syntax tree is currently static, and can run out.
191.rn }` ''