Problems reading in "£" character from a file

Discussion in 'Perl Misc' started by Stephen Adam, Dec 18, 2003.

  1. Stephen Adam

    Stephen Adam Guest

    Hi there,

    I'm having problems when reading in the "£" character from a file, they all
    get converted into u's with an accent (?). Can anyone tell me why this is
    happening and how to avoid it, its got me very confused.

    Just run this program and make sure you place a file the same directory
    called test.txt with some pound signs (£) in it, they keep getting
    mytseriously turned into accented u's.

    Thanks

    Steve

    PS - I'm running Perl on a Windows XP platform if thats any help.




    #!C:/Perl/bin/perl.exe -w


    # This program will read a file in the same directory called test.txt into
    the "$whole" variable and

    # then print it out


    use strict;



    &Datain();


    exit(0);



    sub Datain(){

    our $FILEHANDLE = "./test.txt";
    my $whole;


    open("FILEHANDLE") or
    die ("Unable to open file $FILEHANDLE\n Program Quiting\n");

    while(my $line = <FILEHANDLE>){
    chomp $line; # Get rid of new line char
    $line .=" "; # Put blank space instead
    $line =~ tr/[A-Z]/[a-z]/; # Put line variable into lowercase
    $whole .= $line;
    }

    print "$whole";
    }
     
    Stephen Adam, Dec 18, 2003
    #1
    1. Advertising

  2. Stephen Adam

    Ben Morrow Guest

    "Stephen Adam" <> wrote:
    > Just run this program and make sure you place a file the same directory
    > called test.txt with some pound signs (£) in it, they keep getting
    > mytseriously turned into accented u's.


    This is not a perl problem, it is a problem with DOS windows being
    stupid about character encodings. If you direct your output to a file
    instead you should find that your £s are intact.

    Ben

    --
    'Deserve [death]? I daresay he did. Many live that deserve death. And some die
    that deserve life. Can you give it to them? Then do not be too eager to deal
    out death in judgement. For even the very wise cannot see all ends.'
    :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
     
    Ben Morrow, Dec 18, 2003
    #2
    1. Advertising

  3. Stephen Adam

    Stephen Adam Guest

    Thanks for the help, that one had me stumped for a while.

    Cheers

    Steve
     
    Stephen Adam, Dec 19, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KwikRick
    Replies:
    1
    Views:
    381
    Christos TZOTZIOY Georgiou
    Aug 22, 2003
  2. utab
    Replies:
    1
    Views:
    296
  3. RishiD
    Replies:
    1
    Views:
    323
    red floyd
    Nov 30, 2006
  4. Spacebar265

    Scanning a file character by character

    Spacebar265, Feb 5, 2009, in forum: Python
    Replies:
    18
    Views:
    495
  5. Navaneeth
    Replies:
    29
    Views:
    960
    Jorgen Grahn
    Aug 28, 2010
Loading...

Share This Page