Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello monks!

Edit: I found the solution. I needed to use '>:raw:encoding(UTF-16)' ;)

So I am building a text file that will be imported with a bulk insert into SQL Server. However, since I am using french langage characters, I need the file to be encoded in UTF-16.

Here is what I am doing (this isn't the entire code, just the relevant parts):

my $fileDest = "hostsfile_modified.txt"; die "Problème de création du fichier $fileDest" unless open(my $fd, '> +:encoding(UTF-16)', $fileDest); my $line = ""; #I build my $line... print $fd $line."\n"; close $fd;

Once this is done however, my output document looks something like this:;VL-CX-RP002;RP;CX;SRIP-R;Internet (TPIA)
਀㄀ ⸀㄀㔀㐀⸀㈀⸀㐀㬀嘀䰀ⴀ儀䈀䌀刀ⴀ匀圀  ㄀㬀匀圀㬀儀䈀䌀刀㬀匀刀䤀倀ⴀ刀㬀嘀匀䐀⼀匀䐀嘀ഊ10.154.10.53;VL-VTTV-SW001;SW;VTTV;SRIP-R;VSD/SDV
਀㄀ ⸀㄀ ⸀㈀㐀⸀㤀㜀㬀嘀䰀ⴀ䴀匀ⴀ䔀儀 ㌀㄀㬀䔀儀㬀䴀匀㬀匀刀䤀倀ⴀ䄀㬀ഊ10.10.20.52;VL-MS-EQ033;EQ;MS;SRIP-A;
਀㄀ ⸀㄀ ⸀㈀㐀⸀㤀㠀㬀嘀䰀ⴀ䴀匀ⴀ䔀儀㄀㌀㄀㬀䔀儀㬀䴀匀㬀匀刀䤀倀ⴀ䄀㬀ഊ10.10.20.53;VL-MS-EQ133;EQ;MS;SRIP-A;

I realize that the problem seems to be the new line character however I am not sure what the solution is. Thanks for your help!


In reply to UTF 16 encoding problems by jrvd

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Corion]: marto: I used Padre for some time but then switched to Notepad++, since all the funky features I wanted to put into Padre couldn't be made to work, and/or I lost interest :)
    [Discipulus]: indeed marto I dunno. I tested once and many years ago. But I'm not the programmer yardstick. I try to install Padre via cpan now just to add a line about it in the issue. Strawberryperl all life long!
    [marto]: yeah, when I worked on Windows I did use Np++ all the time

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (11)
    As of 2018-06-25 08:56 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.