Path: utzoo!attcan!uunet!decwrl!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Deleting (Only) First Blank Line in File Message-ID: <8567@jpl-devvax.JPL.NASA.GOV> Date: 2 Jul 90 17:04:03 GMT References: <1651@fallst.UUCP> <1990Jun30.214249.15211@iwarp.intel.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Distribution: comp Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 41 In article emv@math.lsa.umich.edu (Edward Vielmetti) writes: : In article <1990Jun30.214249.15211@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: : : | Solutions other than those using 'perl' are preferred. : : But, since you didn't say *necessary*, how about: : : perl -ne 'print unless /^$/ && $once++;' : : hm, nice. how about this problem: printing the first 10 lines after : a signal line? I would think it could be done with the .. operator, namely : : perl -ne 'if (/===/) {$l = $. + 10 ;} ; if (/===/ .. $l) {print;} ' : : but this prints only the === line and the one following. a test with digits : shows that it works as expected for this: : : perl -ne 'if (/===/) {$l = $. + 10 ;} ; if (/===/ .. 50) {print;} ' : : which lead me to experiment with the following which worked : : perl -ne 'if (/===/) {$l = $. + 10 ;} ; eval "if (/===/ .. $l) {print;}"; ' : : the eval appears to be neccesary in order to force the .. to be : interpreted in a scalar context, but I guess I don't really understand : the man page, & in retrospect a simple loop would have done the trick : OK. The eval doesn't force a scalar context--it forces $l to be a static literal. The arguments to .. are ordinarily interpreted as *boolean expressions*. However If either operand of scalar .. is static, that operand is implicitly compared to the $. variable, the current line number. So /===/ .. 50 is interpreted as /===/ .. ($. == 50). But /===/ .. $l isn't. The scalar .. is in there mostly to emulate sed. Myself, I'd probably go ahead and write a loop too. Larry