Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Problems? Is your data what you think it is?
 
PerlMonks  

(Windows) Encode vs. use open

by Anonymous Monk
on Mar 29, 2005 at 18:01 UTC ( [id://443293]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Mi, 30.03.05 0:44 c:\>cat trans-encode.pl use strict; use diagnostics; use Encode 'from_to'; while (<>) { from_to($_, "shiftjis", "utf8"); print; }; Mi, 30.03.05 0:44 c:\>cat trans-useopen.pl use strict; use diagnostics; use open IN => ':encoding(shiftjis)', OUT => ':utf8'; while (<>) { print; }; Mi, 30.03.05 0:45 c:\>cat sakura_5light.bms *---------------------- HEADER FIELD #PLAYER 1 #GENRE JP-SPIRITUAL POP #TITLE ì¸ëÏîÄ [5key Light] #ARTIST AKITO #BPM 138 #PLAYLEVEL 3 #RANK 3 #TOTAL 0 #STAGEFILE title.bmp %EMAIL %URL Mi, 30.03.05 0:45 c:\>perl trans-encode.pl < sakura_5light.bms > s.ut +x Mi, 30.03.05 0:46 c:\>cat s.utx *---------------------- HEADER FIELD #PLAYER 1 #GENRE JP-SPIRITUAL POP #TITLE µí£ÞÅ»µ£ê [5key Light] #ARTIST AKITO #BPM 138 #PLAYLEVEL 3 #RANK 3 #TOTAL 0 #STAGEFILE title.bmp %EMAIL %URL Mi, 30.03.05 0:46 c:\>rem this above is correct Mi, 30.03.05 0:47 c:\>perl trans-useopen.pl < sakura_5light.bms > s.u +tx Mi, 30.03.05 0:48 c:\>cat s.utx *---------------------- HEADER FIELD #PLAYER 1 #GENRE JP-SPIRITUAL POP #TITLE ì¸ëÏîÄ [5key Light] #ARTIST AKITO #BPM 138 #PLAYLEVEL 3 #RANK 3 #TOTAL 0 #STAGEFILE title.bmp %EMAIL %URL Mi, 30.03.05 0:48 c:\>rem it is passed through unchanged Mi, 30.03.05 0:48 c:\>perl -v|head -9 This is perl, v5.8.6 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 811 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Dec 13 2004 09:52:01

I also tried with :encoding(utf8) instead of plain :utf8, but this didn't matter.

Sample file in uuencode (Total Commander can unpack this):

begin 644 sakura_5light.bms M#0HJ+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2!(14%$15(@1DE%3$0-"B-03$%9 M15(@,0T*(T=%3E)%($I0+5-025))5%5!3"!03U`-"B-4251,12"-]XG8C(X@ M6S5K97D@3&EG:'1=#0HC05)425-4($%+251/#0HC0E!-(#$S.`T*(U!,05E, M159%3"`S#0HC4D%.2R`S#0HC5$]404P@,`T*(U-404=%1DE,12!T:71L92YB 6;7`-"B5%34%)3"`-"B554DP@#0H-"@`` ` end sum -r/size 10317/202

So simple question: why doesn't use open work as documented?

Replies are listed 'Best First'.
Re: (Windows) Encode vs. use open
by jimbojones (Friar) on Mar 29, 2005 at 18:21 UTC
    Hi

    Reading the doc, I think you need a ":std" pragma as well, when you are printing to STDOUT. From "open" pragma doc.

    The :std subpragma on its own has no effect, but if combined with the :utf8 or :encoding subpragmas, it converts the standard filehandles (STDIN, STDOUT, STDERR) to comply with encoding selected for input/output handles. For example, if both input and out are chosen to be :utf8, a :std will mean that STDIN, STDOUT, and STDERR are also in :utf8. On the other hand, if only output is chosen to be in :encoding(koi8r), a :std will cause only the STDOUT and STDERR to be in koi8r. The :locale subpragma implicitly turns on :std
      That helped. I found out that "combining" works only by putting a use open ':std'; statement after the original pragma.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://443293]
Approved by moot
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.