Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Japanese encoding in Perl

Options
  • 21-04-2006 4:21pm
    #1
    Registered Users 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