Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opening & writing to UTF-8 files; copyright symbol again -- solution

2 views
Skip to first unread message

Highsmith, Anne L

unread,
Nov 13, 2015, 5:15:03 PM11/13/15
to perl...@perl.org

I should probably say, “apparent solution” ‘cause character set issues never seem to end.

 

However, combining Jon Gorman’s recommendation with some Googling, I get:

 

my $outfile='4788022.edited.bib';

open (my $output_marc, '>', $outfile) or die "Couldn't open file $!" ;

binmode($output_marc, ':utf8');

 

The open statement may not be quite correct, as I am not familiar with the more current techniques for opening file handles that John mentioned. However, when I use those instructions to open the output file rather than what I had before, the copyright symbol does indeed come across as C2 A9 as it was in the original record. I didn’t want to use the utf8, because I’ve tried that before and ended up with double-encoding (and a real mess). But I’ll continue testing.

 

The results of the googling I referred to can be found at: https://groups.google.com/forum/#!topic/perl.perl4lib/sy7hqiBQ1yM

 

 

Anne L. Highsmith

Director, Consortia Systems

TAMU Libraries

5000 TAMU

College Station, TX   77843-5000

979 862 4234

his...@tamu.edu

 

Colin Campbell

unread,
Nov 16, 2015, 5:00:01 AM11/16/15
to perl...@perl.org
On Fri, Nov 13, 2015 at 10:05:01PM +0000, Highsmith, Anne L wrote:
> I should probably say, "apparent solution" 'cause character set issues never seem to end.
>
> However, combining Jon Gorman's recommendation with some Googling, I get:
>
> my $outfile='4788022.edited.bib';
> open (my $output_marc, '>', $outfile) or die "Couldn't open file $!" ;
> binmode($output_marc, ':utf8');
>
You can set the correct encoding succinctly on opening files
e.g. open my $fh, '>:encoding(UTF-8)', $outfile

Hope that helps
C.

--
Colin Campbell
Chief Software Engineer,
PTFS Europe Limited
Content Management and Library Solutions
+44 (0) 800 756 6803 (phone)
+44 (0) 7759 633626 (mobile)
colin.c...@ptfs-europe.com
skype: colin_campbell2

http://www.ptfs-europe.com
0 new messages