£ character changing to u.

Discussion in 'CIW Certifications' started by stuPeas, Dec 22, 2006.

  1. stuPeas

    stuPeas Megabyte Poster

    774
    12
    76
    I have an array with various characters stored in it. When i access the English pound symbol (£), Perl seems to be interpreting it as a u letter with a squiggle across the top. Its fine when i actually type the pound sign at the command prompt, the problem only occurs when the script is run.

    Any help greatly appreciated, thanx,:oops:
     
    Certifications: C&G Electronic, CIW Associate (v5).
    WIP: CIW (Website Design Manager)
  2. BosonMichael
    Honorary Member Highly Decorated Member Award 500 Likes Award

    BosonMichael Yottabyte Poster

    19,183
    500
    414
    I'm guessing it's because Perl uses Unicode, not normal ASCII. The Unicode value for £ is 00A3, if that helps. If that doesn't work for you, check here.
     
    Certifications: CISSP, MCSE+I, MCSE: Security, MCSE: Messaging, MCDST, MCDBA, MCTS, OCP, CCNP, CCDP, CCNA Security, CCNA Voice, CNE, SCSA, Security+, Linux+, Server+, Network+, A+
    WIP: Just about everything!
  3. zimbo
    Honorary Member

    zimbo Petabyte Poster

    5,215
    99
    181
    try what Michael said... i had a similar problem in Java... just trying to find what i did to fix it! :rolleyes:
     
    Certifications: B.Sc, MCDST & MCSA
    WIP: M.Sc - Computer Forensics
  4. stuPeas

    stuPeas Megabyte Poster

    774
    12
    76
    This is what im using to test[
    CODE]my @char=qw($ & £ & $ &);
    print("$char[2]");[/CODE]

    Ive tried inserting \u{00A3} instead of £ but it just prints out \u{00A3} instead.

    Ive also tried \x{A3}, with the same result as above.
     
    Certifications: C&G Electronic, CIW Associate (v5).
    WIP: CIW (Website Design Manager)
  5. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    This is a standard problem if you aren't careful about character sets and 'locale'.

    You don't say what OS and version this is - or how you are displaying the results.

    I've just tried your code on a Putty session to a FreeBSD box (because that is where I have perl installed) and it worked as you would expect.

    What actual character are you getting? Is it ú, û, ü or ũ, or something else?

    As far as I know Perl doesn't normaly use Unicode (it is Java that does), but uses ISO 8859 of whatever flavour happens to be set in the environment.

    Use of characters outside of standard 'ASCII' is always fraught with problems unless you control the environment carefully.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  6. stuPeas

    stuPeas Megabyte Poster

    774
    12
    76
    the symbol im getting is the first one you said(ú,).
    os=Win98
    regional settings=English(UK)
    currency symbol=£
    position(whatever that is)=1.1 with a funny symbol in front
     
    Certifications: C&G Electronic, CIW Associate (v5).
    WIP: CIW (Website Design Manager)
  7. BosonMichael
    Honorary Member Highly Decorated Member Award 500 Likes Award

    BosonMichael Yottabyte Poster

    19,183
    500
    414
    Perl came with Unicode support around version 5.8. Just throwing that suggestion out there, since others have had that same issue with display of £ with Unicode.

    In any case, you are correct about different character sets. If it's not Unicode, it's something other than standard ASCII.
     
    Certifications: CISSP, MCSE+I, MCSE: Security, MCSE: Messaging, MCDST, MCDBA, MCTS, OCP, CCNP, CCDP, CCNA Security, CCNA Voice, CNE, SCSA, Security+, Linux+, Server+, Network+, A+
    WIP: Just about everything!
  8. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Aha! Then I think I know what is happening. You are probably doing this in a DOS box?

    If so the problem is because your DOS box is set to display using the old CodePage system - CP850 perhaps. This had completely different mappings for characters with the top bit set.

    I'll have to dig some old docs out on how to fix this.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  9. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Yes - after my previous post I double checked, and I see that 5.6 introduced Unicode support. However I see that it has to be explicitly switched on.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  10. stuPeas

    stuPeas Megabyte Poster

    774
    12
    76
    How do i go about doing that exactly?
     
    Certifications: C&G Electronic, CIW Associate (v5).
    WIP: CIW (Website Design Manager)
  11. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    I doubt that it would help, as Win98 doesn't really support Unicode.

    As my dinner this evening degenerated into serious drinking I'm not in a position to look much up at the moment. I'll take a look in the morning! :oops:

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  12. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    I've now had a chance to boot my Win98SE box and have a play. As I thought, the DOS box uses CP850 by default rather than CP1252.

    I am assuming that you are editing the code in something like wordpad, and running it in a DOS box. If this is not the case *please* tell me so I can revisit this.

    You have the following choices:
    1) Don't do that! :p (i.e. - if you are learning perl steer clear of non-ASCII characters like £)
    2) Edit the code in a DOS box using EDIT - this will use CP850 character set by default so the code when run will look right.
    3) (Messy) replace the DOS box font with one that uses CP1252. This will have the side effect of possibly making anything else run in the DOS box look wrong, particularly if it uses the line-drawing characters.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  13. stuPeas

    stuPeas Megabyte Poster

    774
    12
    76
    Brilliant Harry, you are a genious, thanks LOOOADS.
     
    Certifications: C&G Electronic, CIW Associate (v5).
    WIP: CIW (Website Design Manager)

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.