Oops - teaches me not to test my solution :). Both suffer from not adding a newline to the last element of the join. You could stick a newline at the end, but doing so naively will generate a number of empty lines. The simplest thing is probably:
while(<>) { print join("", map { "$_ lineno $.\n" } /(string)/g); } This way you just stick the newline in the bit you are creating. If you are willing to risk someone changing the output field separator ($,) on you, you can use an implicit join: while(<>) { print map { "$_ lineno $.\n" } /(string)/g; } On Friday, September 6, 2002, at 11:33 PM, Harry Putnam wrote: > George Schlossnagle <[EMAIL PROTECTED]> writes: > >> while(<>) { >> print join("\n", map { "$_ lineno $." } /(string)/g); >> } > > George, I haven't gotten good results with either of the pieces of > code you posted. This one gives me. > > string lineno 1 > string lineno 1string lineno 2 <no newline here> > > I can fix the ending newline easy enough but that one in the middle > seems more difficult. > > > The first one you posted had the same problem: > > while(<>) { > print join("\n", /(string)/g); > } > > string > stringstring<no newline> > > > It seems lines with multiple matches throw a monkey wrench into it > where as the `push @array,$_ =~ /(string)/g' approach doesn't have > that problem. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > // George Schlossnagle // Principal Consultant // OmniTI, Inc http://www.omniti.com // (c) 240.460.5234 (e) [EMAIL PROTECTED] // 1024D/1100A5A0 1370 F70A 9365 96C9 2F5E 56C2 B2B9 262F 1100 A5A0 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]