Path: utzoo!attcan!uunet!lll-winken!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Behavior of a2p Message-ID: <8587@jpl-devvax.JPL.NASA.GOV> Date: 3 Jul 90 21:41:23 GMT References: <182@sun13.scri.fsu.edu> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 45 In article <182@sun13.scri.fsu.edu> nall@sun8.scri.fsu.edu (John Nall) writes: : 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. After the next patch, a2p will throw in a chop if it sees NF. Way 2 would run into the problem that NF could be too small if trailing fields were null. Larry