Re: catching utf8 errors

2015-03-15 Thread Manfred Lotz
On Sun, 15 Mar 2015 23:26:41 +1300 Kent Fredric wrote: > On 15 March 2015 at 21:41, Manfred Lotz wrote: > > > I agree but I thought that in this case I would need to know the > > potential warning messages the :encoding(UTF-8) could issue in > > order to take action in those particular cases. >

Re: catching utf8 errors

2015-03-15 Thread Kent Fredric
On 15 March 2015 at 21:41, Manfred Lotz wrote: > I agree but I thought that in this case I would need to know the > potential warning messages the :encoding(UTF-8) could issue in order to > take action in those particular cases. > > Using a section local > { >open( local *STDERR,'>', $err); >

Re: catching utf8 errors

2015-03-15 Thread Manfred Lotz
On Sun, 15 Mar 2015 21:11:05 +1300 Kent Fredric wrote: > On 15 March 2015 at 20:07, Manfred Lotz wrote: > > > I prefer the method Charles showed. But nevertheless your method is > > interesting as well. > > > > FWIW, SIG{__WARN__} is much preferred over redirecting stderr to > simply suppress/

Re: catching utf8 errors

2015-03-15 Thread Kent Fredric
On 15 March 2015 at 20:07, Manfred Lotz wrote: > I prefer the method Charles showed. But nevertheless your method is > interesting as well. > FWIW, SIG{__WARN__} is much preferred over redirecting stderr to simply suppress/capture/filter warnings. For instance, if somebody passes an object to w

Re: catching utf8 errors

2015-03-15 Thread Manfred Lotz
I prefer the method Charles showed. But nevertheless your method is interesting as well. Thanks for sharing, Manfred On Sat, 14 Mar 2015 14:24:48 -0400 Brandon McCaig wrote: > On Sat, Mar 14, 2015 at 03:20:06AM -0700, Charles DeRykus wrote: > > open my $fh, '<:encoding ) or die ... > > >

Re: catching utf8 errors

2015-03-14 Thread Brandon McCaig
On Sat, Mar 14, 2015 at 03:20:06AM -0700, Charles DeRykus wrote: > open my $fh, '<:encoding ) or die ... > > { open( local *STDERR,'>',\my $err); >my $string = <$fh>; > if ($err =~ /does not map to Unicode/) { > # take action. > } > } Here is an alternative appro

Re: catching utf8 errors

2015-03-14 Thread Manfred Lotz
On Sat, 14 Mar 2015 03:20:06 -0700 Charles DeRykus wrote: > On Sat, Mar 14, 2015 at 2:38 AM, Manfred Lotz > wrote: > > Hi all, > > I wanted to test what happens if Perl encounters an error when > > reading a utf8 encoded file. > > > > Here a minimal example: > > > > #! /usr/bin/perl > > > > use

Re: catching utf8 errors

2015-03-14 Thread Manfred Lotz
On Sat, 14 Mar 2015 23:18:42 +1300 Kent Fredric wrote: > On 14 March 2015 at 22:38, Manfred Lotz wrote: > > > following error message which is fine. > > > Sorry for being pedantic, but I think you'll find that those are what > we call "warnings", not "errors". > > Errors tend to be fatal. >

Re: catching utf8 errors

2015-03-14 Thread Charles DeRykus
On Sat, Mar 14, 2015 at 2:38 AM, Manfred Lotz wrote: > Hi all, > I wanted to test what happens if Perl encounters an error when reading > a utf8 encoded file. > > Here a minimal example: > > #! /usr/bin/perl > > use strict; > use warnings; > > my $fname = $ARGV[0]; > > open my $fh, '<:encoding(UTF

Re: catching utf8 errors

2015-03-14 Thread Kent Fredric
On 14 March 2015 at 22:38, Manfred Lotz wrote: > following error message which is fine. Sorry for being pedantic, but I think you'll find that those are what we call "warnings", not "errors". Errors tend to be fatal. However, curiously, "<:utf8" 's warnings seems to be regulated by the warnin

catching utf8 errors

2015-03-14 Thread Manfred Lotz
Hi all, I wanted to test what happens if Perl encounters an error when reading a utf8 encoded file. Here a minimal example: #! /usr/bin/perl use strict; use warnings; my $fname = $ARGV[0]; open my $fh, '<:encoding(UTF-8)', $fname or die "Couldn't open file: $fname"; my $string = <$fh>; clo