For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2006 > Re: xA0 ( decimal 160 ) in code fixed from email $_ =~ s/\xA0/ /g;









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: xA0 ( decimal 160 ) in code fixed from email $_ =~ s/\xA0/ /g;
Tom Phoenix

2006-03-22, 9:57 pm

On 3/22/06, Alan_C <acelists@gmail.com> wrote:

> In emails I'm receiving from this list when I've copy/pasted into editor =

then
> save the file as Perl script gives the file many of the decimal 160 (as
> reported by perltidy) characters. Perl (when attempt to run said script)
> reports such character on the commandline as xA0


This character is, I believe, the "non-breaking space". It's often
used in rendering code which might otherwise not be properly formatted
in a web browser, but it ruins the code for copy-and-paste.

> $_ =3D~ s/\xA0/ /g; # xA0 to space


You've got the exact right idea. I hesitate to post this one-liner,
because there's nothing really wrong with the program you posted. But
I use something like this for similar fixups:

perl -pi.bak -e 'tr/\xA0/ /' filenames*

Perl has a number of command-line options that are useful for simple
file transformations, so that's how the -p and -i.bak replaced most of
your code. (perlrun manpage.)

The tr/// (perlop) is the transliteration operator, and it should be
*slightly* more efficient at this kind of operation. (I say, it should
be, but there's no substitute for benchmarking, and your data may
vary. And, slightly.) But that's how I'd write it.

Cheers!

--Tom Phoenix
Stonehenge Perl Training
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com