Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Japanese encoding in Perl

  • 21-04-2006 04:21PM
    #1
    Registered Users, Registered Users 2 Posts: 90 ✭✭


    Hi, it's my first time dealing with a foreign character set in Perl and I'm having a few problems.

    For the moment I just want to read in a file which is encoded in Unicode and output each line to another file (later I want to deal with regexs, but I wanted to start off simple). When I open the new output file it doesn't match the original. Could someone please tell me where I'm going wrong? Cheers + here's the code I've written so far.

    #!/usr/bin/perl

    $inFile=$ARGV[0];
    $outFile=$ARGV[1];

    open (IN, $inFile) || die "cannot open file: $inFile\n";
    chomp(@lines = <IN>);
    close (IN);

    open (OUT, "$outFile") || die "cannot write to file: $outFile\n";
    for($i = 0; $i <= $#lines; $i++) {
    print OUT "$lines[$i]\n";
    }


Comments

  • Closed Accounts Posts: 304 ✭✭Zaltais


    Untested, but should work...
    #!/usr/bin/perl
    
    use warnings;
    use strict;
    
    my $inFile=$ARGV[0];
    my $outFile=$ARGV[1];
    
    open(IN, $inFile) || die "cannot open file: $inFile : $!";
    my @lines = <IN>;
    close(IN);
    
    open(OUT, $outFile) || die "cannot write to file: $outFile : $!";
    
    foreach my $line (@lines){
        print OUT $line;
    }
    
    close(OUT);
    

    Any questions relating to any of the above, just ask...


Advertisement