[opensource] Command line question

Jim Dinan dinan at cse.ohio-state.edu
Sun Jun 4 12:11:01 EDT 2006


> it looks like it just replaces newlines with spaces.
> what's the $. % 16 part?

Re: perl -pe '($. % 16 != 0) and s/\n/ /'

It says, if the current line number ($.) is not a multiple of 16 (line
numbers start counting at 1) then replace newlines with spaces.

The -p flag on the command line wraps that statement into:
while (<>) {
	($. % 16 != 0) and s/\n/ /;
	print;
}

Which will automatically read a line of input, run my command, then
print the output.  All of this is happening behind the scenes through
the $_ variable.  $_ is the default variable in Perl.  It's the 'it' in
"Print it".

So, if the line number is a multiple of 16, the newline will be printed
out.  Otherwise it will be replaced with a space before being printed.  :)

 - jim.

-- 
James Dinan <dinan at cse.ohio-state.edu>

Graduate RA - Computer Science and Engineering
              The Ohio State University


More information about the Opensource mailing list