Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!rutgers!mephisto!prism!sun13!sun8.scri.fsu.edu!nall From: nall@sun8.scri.fsu.edu (John Nall) Newsgroups: comp.lang.perl Subject: Behavior of a2p Message-ID: <182@sun13.scri.fsu.edu> Date: 3 Jul 90 15:01:22 GMT Sender: news@sun13.scri.fsu.edu Reply-To: nall@sun8.scri.fsu.edu (John Nall) Organization: Supercomputer Computations Research Institute Lines: 45 In converting a few awk scripts using a2p, it seems that the behavior of a2p is not exactly what I think it should be. (This is pretty nit-picky, I realize...:-) ) As an example: Consider the following awk script: {print NF} a2p would convert this into the following (leaving out some of the header material): $[ = 1; $, = ' '; $\ = "n"; while (<>) { $Fld = split(' ', $_, 999); print $#Fld; } Now consider one line of data, consisting of the following: 1 2 3 4 5 The awk version would print 5, saying there are 5 fields. The perl version, produced by a2p, would print 6, saying there are 6 fields. One can "fix" the perl version in either one of two ways: (1) by adding chop; after the while(<>) { or (2) by changing the split to "split(' ',$_). The behavior of split without the LIMIT being specified is, of course, documented. So it would seem that the scripts produced by a2p, in order to give the same result as the original awk script, should do one of these two things, since it is fairly common for awk scripts to assume that NF is going to be the actual number of fields. -- John W. Nall | Supercomputation Computations Research Institute nall@sun8.scri.fsu.edu | Florida State University, Tallahassee, FL 32306 "They said it couldn't be done/they said nobody could do it/ But he tried the thing that couldn't be done!/He tried - and he couldn't do it"