Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^6: how to output file in Unicode

by anakin30 (Acolyte)
on Aug 27, 2012 at 11:18 UTC ( #989965=note: print w/ replies, xml ) Need Help??


in reply to Re^5: how to output file in Unicode
in thread how to output file in Unicode

I have written this script below,

the output file generated but i still seeing, German "Umlaut" in the csv output file. Example : Björn

why the csv output file is not encoded into encoding(UTF-8)??, am i missed any steps here!!!!

#!/usr/bin/perl use Net::LDAP; use Encode; use Net::LDAP::Entry; use Net::LDAP::Control::Paged; use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); #$outputfile = "LicMan1.csv"; $outputfile = 'C:\Meta\MDS\data\out\LicMan1.csv'; #$inputfile = 'D:\Meta\MDS\data\out\LicMan1.csv'; $outputfile2 = 'C:\Meta\MDS\data\out\LicMan.csv'; open (FH, ">$outputfile") or die "$!"; print FH "import_id;import_data_source_id;login;import_level_2_id;impo +rt_location_id;last_name;first_name;email;is_active;language;remarks; +\n"; my @args = ( base => $base, scope => 'sub', filter => $query, attrs => \@attrs, control => [ $page ],); my $cookie; while (1) { $mesg = $ldap->search ( @args ) or die $!; while (my $entry = $mesg->shift_entry()) { #uid,dpwncrestcode,dpwnc,sn,givenname,mail,dhlaccountstatus,preferredl +anguage,dhlemployeetype my $entrydn = $entry->dn(); my $uid = $entry->get_value('uid'); my $dpwncrestcode = $entry->get_value('dpwncrestcode'); my $dpwnc = $entry->get_value('dpwnc'); my $sn = $entry->get_value('sn'); if (($sn eq "") || ($sn eq " ")){ $sn = "-"; } else { $sn = "$sn";} my $givenname = $entry->get_value('givenname'); if (($givenname eq "") || ($givenname eq " ")){ $givenname = "-"; } else { $givenname = "$givenname";} my $mail = $entry->get_value('mail'); my $dhlaccountstatus = $entry->get_value('dhlaccountstatus'); if ($dhlaccountstatus == "enabled") { $dhlaccountstatus = "1"; } else { $dhlaccountstatus = "0";} my $preferredlanguage = $entry->get_value('preferredlanguage'); if ($preferredlanguage ne "de") { $preferredlanguage = "en"; } else { $preferredlanguage = "de";} my $dhlemployeetype = $entry->get_value('dhlemployeetype'); if ($dhlemployeetype eq "") { $dhlemployeetype = ";"; } else { $dhlemployeetype = "$dhlemployeetype";} print FH "$uid;dpdhl_eds;$uid;$dpwncrestcode;$dpwnc;$sn;$givenname;$ma +il;$dhlaccountstatus;$preferredlanguage;$dhlemployeetype\n"; } } $ldap->unbind; close(FH); open (INPUT, "<:encoding(UTF-8)", $outputfile) or die "Cannot open fil +ename for input: $!"; while (<INPUT>) { s/"//g; $replace .= $_;} close INPUT or die "Cannot close filename: $!"; open (OUTPUT, ">:encoding(UTF-8)",$outputfile2) or die "Cannot open fi +lename for output: $!"; print OUTPUT $replace; close OUTPUT or die "Cannot close filename: $!";


Comment on Re^6: how to output file in Unicode
Download Code
Re^7: how to output file in Unicode
by remiah (Hermit) on Aug 27, 2012 at 12:07 UTC
    So, what's going on if first open, let it open with utf-8 io layer?
    open (FH, ">$outputfile") or die "$!";
    revise to
    open (OUTPUT, ">:encoding(UTF-8)",$outputfile or die "$!";
    What is the result?

    update:
    Second question: Is that $givenname?

      result is negative, i still see the givenname is not converted to Unicode UTF8, Example : Björn

      i edit the script as below, but it doesn't help

      open (OUTPUT, ">:encoding(UTF-8)",$outputfile) or die "Cannot open filename for input: $!";

      how about using perl module (utf8::all) does it help?

      yeah this is givenname :)

        One question. What do you use when you said "Björn"? I mean Browser? or Editor?

        Back to previous.

        open (OUTPUT, ">",$outputfile) or die "Cannot open filename for input: + $!";
        And Open your output file with Browser.What do you see when you change "Character Encoding" of Browser? Can you change it to UTF-8?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-08-27 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (244 votes), past polls