Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Unregognized character \xA0

by Anonymous Monk
on Feb 02, 2004 at 01:34 UTC ( #325765=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

What's wrong with my hash? It says the error occurs on the line of "two" => "2"
my %numbers = ( "one" => "1", "two"  => "2", "three" => "3" ); print $numbers{"one"};

Replies are listed 'Best First'.
Re: Unregognized character \xA0
by jbware (Chaplain) on Feb 02, 2004 at 01:56 UTC
    The \xA0 is an unprintable character that somehow got into your text. You can either open it up in a hex-capable editor to see where it is or you can just clean all the whitespace out of, and around, the hash. Or, just copy and paste off the PM webpage (not using the "download code" function. That should clear this particular situation up.

    - jbWare
      Actually, "\xA0" is a "non-breaking space" in "Latin1" (ISO 8859-1). I would expect an app like MS-Word to produce a byte like this if it were "preceded" (or "followed", depending on your notion of byte order) by a null byte, indicating UTF-16 encoding. But then I'd expect perl to complain about null bytes (but maybe it wouldn't -- I haven't tried). Or, if Word was using Latin1 as its output encoding (but that seems unexpected).
      Okay, thank you. I copied this from a website, there was text formatting when I copied it over into Notepad so maybe that's where the unseen character was hiding. I deleted it and rewrote it myself in Notepad and everything works fine. Very, very weird, but it's all good now. Thanks wise monks!
Re: Unregognized character \xA0
by BrowserUk (Pope) on Feb 02, 2004 at 01:55 UTC

    Update: Whoops! Guess who just noticed the title of the node. Sorry {blush}!

    You appear to have some embedded xAO characters in your code? It would have been helpful if you had told us what the error message was! Is it

    Unrecognized character \xA0 at ...?

    Are you editing your source files using WORD?

    If so, stop. Use notepad, or better still, get yourself a proper code editor, there are plenty available for free on the web.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Timing (and a little luck) are everything!

Re: Unregognized character \xA0
by Roger (Parson) on Feb 02, 2004 at 01:43 UTC
    Let me guess, you have recently copied a perl script from DOS/Windows to Unix/Linux, and you didn't convert it to unix format...

    Use vi... (^V^M = [Ctrl-V][Ctrl-M])
    vi file.pl :%s/^V^M//g :x

    or use the dos2unix utility.

      No, I'm writing this myself. My complete script looks like the one at the bottom of this node. But you're right, this IS running on Windows.
      #!/usr/bin/perl use strict; use warnings; my %numbers = ( "one" => "1", "two"  => "2", "three" => "3" ); print $numbers{"one"};
        Ok, seems to me that your problem is actually the other-way-round. You created the file in unix format and it does not run under DOS/Windows. Just run the utility unix2dos to convert your script from unix format to dos format.

        Update:

        I copied this from a website, there was text formatting when I copied it over into Notepad ...

        Aha, you didn't mention about that. Problem solved... ;-)

Re: Unregognized character \xA0
by bart (Canon) on Feb 02, 2004 at 08:52 UTC
    Your source code contains a non-breaking space character, chr(160). Perl can't have that in its source code — only in quoted strings. Please replace it by ordinary whitespace, be it spaces, tabs, newlines...

      Non-breaking space, wow, that didn't occur to me. I knew \xA0 was aacute in cp852 (and cp437 also).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://325765]
Approved by Roger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2019-02-18 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I use postfix dereferencing ...









    Results (99 votes). Check out past polls.

    Notices?