[32309] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3576 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 26 11:09:23 2011

Date: Mon, 26 Dec 2011 08:09:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 26 Dec 2011     Volume: 11 Number: 3576

Today's topics:
    Re: Opening Unicode files? r.mariotti@fdcx.net
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 26 Dec 2011 09:13:48 -0500
From: r.mariotti@fdcx.net
Subject: Re: Opening Unicode files?
Message-Id: <j60hf7dm92s073kd0kfde300dqc2hfau36@4ax.com>

On Sun, 25 Dec 2011 01:52:10 +0000 (UTC), Ilya Zakharevich
<nospam-abuse@ilyaz.org> wrote:

>Does Perl ship with a simple method of opening Unicode files?  E.g., I
>would like to have something like
>
>   open my $fh, '< :BOM0or(utf8)', $filename
>
>where BOM0or does what Perl itself does for Perl files: it looks for the
>first 4 bytes; given that a Perl file starts in ASCII, one can detect
>BOMs, can detect UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE, or see that it
>is none of the above (then the arument in parens explains what to do;
>e.g., Perl itself does BOM0or(latin1)).
>
>Likewise, if one does not know that the file starts in ASCII, one can
>still detect BOM (which does not appear often in the encodings I know)
>so one could do  :BOMor(utf8).  Do not recollect seeing such support
>for files open()ed by Perl programs; is there?
>
>Thanks,
>Ilya


Here's what I use and it seems to do what's needed:

use File::BOM qw( :all );

# Open specified input file
open(IFH, '<:via(File::BOM)', $IF) or die "Could NOT open specified
file ($IF)!\n";


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3576
***************************************


home help back first fref pref prev next nref lref last post