SPUG: itm 60 in effective perl programming

John W. Krahn krahnj at telus.net
Thu Feb 24 01:53:45 PST 2005

Tim Maher wrote:
> On Wed, Feb 23, 2005 at 11:46:28PM -0800, Florentin Ionescu wrote:
>>perl -pe 's/\n/" " . <>/e' file
>>is presented in Effective perl programming as program to
>>join lines from a file. what does it mean <> in this context
>>? - I looked into perlop and perlre but can't figure out haw
>>it works.
> <> is the "input operator"
              readline operator

> -- it's like the UNIX shell's "read"
> command, except it loads $_ with the next line of input

IIF it is used in a while loop conditional!

> rather than some other variable.  
> But IMHO, that's a pretty inscrutable way to join lines.  Here's a more
> "scrutable" way, based on the implicit loop (-p), assuming you really
> want a space between each pair of lines as shown above:
> perl -wpe 's/\n$/ /;' file	# replace newline with space

That replaces *every* newline with a space unlike the OP's example which
replaces every odd numbered newline with a space.  Also, the end of line
anchor ($) is superfluous as there is only one newline in every line (unless
you change the Input Record Separator.)

use Perl;

More information about the spug-list mailing list