summaryrefslogtreecommitdiff
path: root/x2p/a2p.man
diff options
context:
space:
mode:
authorLarry Wall <larry@wall.org>1989-10-18 00:00:00 +0000
committerLarry Wall <larry@wall.org>1989-10-18 00:00:00 +0000
commita687059cbaf2c6fdccb5e0fae2aee80ec15625a8 (patch)
tree674c8533b7bd942204f23782934c72f8624dd308 /x2p/a2p.man
parent13281fa4f8547e0eb31d1986b865d9b7ec7d0dcc (diff)
downloadperl-a687059cbaf2c6fdccb5e0fae2aee80ec15625a8.tar.gz
perl 3.0: (no announcement message available)perl-3.000
A few of the new features: (18 Oct) * Perl can now handle binary data correctly and has functions to pack and unpack binary structures into arrays or lists. You can now do arbitrary ioctl functions. * You can now pass things to subroutines by reference. * Debugger enhancements. * An array or associative array may now appear in a local() list. * Array values may now be interpolated into strings. * Subroutine names are now distinguished by prefixing with &. You can call subroutines without using do, and without passing any argument list at all. * You can use the new -u switch to cause perl to dump core so that you can run undump and produce a binary executable image. Alternately you can use the "dump" operator after initializing any variables and such. * You can now chop lists. * Perl now uses /bin/csh to do filename globbing, if available. This means that filenames with spaces or other strangenesses work right. * New functions: mkdir and rmdir, getppid, getpgrp and setpgrp, getpriority and setpriority, chroot, ioctl and fcntl, flock, readlink, lstat, rindex, pack and unpack, read, warn, dbmopen and dbmclose, dump, reverse, defined, undef.
Diffstat (limited to 'x2p/a2p.man')
-rw-r--r--x2p/a2p.man66
1 files changed, 34 insertions, 32 deletions
diff --git a/x2p/a2p.man b/x2p/a2p.man
index 858ee53272..45d8ea93bb 100644
--- a/x2p/a2p.man
+++ b/x2p/a2p.man
@@ -1,7 +1,13 @@
.rn '' }`
-''' $Header: a2p.man,v 2.0 88/06/05 00:15:36 root Exp $
+''' $Header: a2p.man,v 3.0 89/10/18 15:34:22 lwall Locked $
'''
''' $Log: a2p.man,v $
+''' Revision 3.0 89/10/18 15:34:22 lwall
+''' 3.0 baseline
+'''
+''' Revision 2.0.1.1 88/07/11 23:16:25 root
+''' patch2: changes related to 1985 awk
+'''
''' Revision 2.0 88/06/05 00:15:36 root
''' Baseline version 2.0.
'''
@@ -74,7 +80,7 @@ might say:
.sp
a2p -7 -nlogin.password.uid.gid.gcos.shell.home
.sp
-Any delimiter will do to separate the field names.
+Any delimiter can be used to separate the field names.
.TP 5
.B \-<number>
causes a2p to assume that input will always have that many fields.
@@ -85,17 +91,6 @@ 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.
.PP
-The split operator in perl always strips off all null fields from the end.
-Awk does NOT do this, if you've set FS.
-If the perl script splits to an array, the field count may not reflect
-what you expect.
-Ordinarily this isn't a problem, since nonexistent array elements have a null
-value, but if you rely on NF in awk, you could be in for trouble.
-Either force the number of fields with \-<number>, or count the number of
-delimiters another way, e.g. with y/:/:/.
-Or add something non-null to the end before you split, and then pop it off
-the resulting array.
-.PP
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
@@ -110,6 +105,8 @@ 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 \*(L"#???\*(R".
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.
.PP
Perl does not attempt to emulate the behavior of awk in which nonexistent
array elements spring into existence simply by being referenced.
@@ -133,20 +130,9 @@ Perl has two kinds of array, numerically-indexed and associative.
Awk arrays are usually translated to associative arrays, but if you happen
to know that the index is always going to be numeric you could change
the {...} to [...].
-Iteration over an associative array is done with each(), but
+Iteration over an associative array is done using the keys() function, but
iteration over a numeric array is NOT.
-You need a for loop, or while loop with a pop() or shift(), so you might
-need to modify any loop that is iterating over the array in question.
-.PP
-Arrays which have been split into are assumed to be numerically indexed.
-The usual perl idiom for iterating over such arrays is to use pop() or shift()
-and assign the resulting value to a variable inside the conditional of the
-while loop.
-This is destructive to the array, however, so a2p can't assume this is
-reasonable.
-A2p will write a standard for loop with a scratch variable.
-You may wish to change it to a pop() loop for more efficiency, presuming
-you don't want to keep the array around.
+You might need to modify any loop that is iterating over the array in question.
.PP
Awk starts by assuming OFMT has the value %.6g.
Perl starts by assuming its equivalent, $#, to have the value %.20g.
@@ -157,24 +143,40 @@ the awk script.
There are times when you can move this down past some conditionals that
test the entire record so that the split is not done as often.
.PP
-There may occasionally be extra parentheses that you can remove.
-.PP
For aesthetic reasons you may wish to change the array base $[ from 1 back
-to the default of 0, but remember to change all array subscripts AND
+to perl's default of 0, but remember to change all array subscripts AND
all substr() and index() operations to match.
.PP
-Cute comments that say "# Here is a workaround because awk is dumb" are not
-translated.
+Cute comments that say "# Here is a workaround because awk is dumb" are passed
+through unmodified.
.PP
Awk scripts are often embedded in a shell script that pipes stuff into and
out of awk.
Often the shell script wrapper can be incorporated into the perl script, since
perl can start up pipes into and out of itself, and can do other things that
awk can't do by itself.
+.PP
+Scripts that refer to the special variables RSTART and RLENGTH can often
+be simplified by referring to the variables $`, $& and $', as long as they
+are within the scope of the pattern match that sets them.
+.PP
+The produced perl script may have subroutines defined to deal with awk's
+semantics regarding getline and print.
+Since a2p usually picks correctness over efficiency.
+it is almost always possible to rewrite such code to be more efficient by
+discarding the semantic sugar.
+.PP
+For efficiency, you may wish to remove the keyword from any return statement
+that is the last statement executed in a subroutine.
+A2p catches the most common case, but doesn't analyze embedded blocks for
+subtler cases.
+.PP
+ARGV[0] translates to $ARGV0, but ARGV[n] translates to $ARGV[$n].
+A loop that tries to iterate over ARGV[0] won't find it.
.SH ENVIRONMENT
A2p uses no environment variables.
.SH AUTHOR
-Larry Wall <lwall@devvax.Jpl.Nasa.Gov>
+Larry Wall <lwall@jpl-devvax.Jpl.Nasa.Gov>
.SH FILES
.SH SEE ALSO
perl The perl compiler/interpreter