[Pdx-pm] command line options
Bruce J Keeler
bruce at gridpoint.com
Wed May 19 16:44:48 CDT 2004
On Wed, 2004-05-19 at 14:01, Thomas J Keller wrote:
> Hi all,
> Simple question, but I can't find the answer.
> I want to do the simplest thing: read a tab delimited file with Mac
> ('\cM' carriage return) endings, and remove extra whitespace.
>
> I wrote this on the command line:
> perl -i.bak -pe 'local $/ = "\cM'; s/[\s\t]+/\t/g;' input.txt
This is equivalent to:
while (<>) {
local $/ = "\cM";
s/[\s\t]+/\t/g;
print;
}
The 'local $/ = "\cM"' statement is in the wrong place to influence the
behavior of the '<>', so the whole file is being read in at once, and
the regex only runs once. That's problem #1.
Problem #2 is that \s matches the carriage-returns, so they're getting
eaten and replaced with tabs.
Bruce
More information about the Pdx-pm-list
mailing list