On Sat, 14 Mar 2015 23:18:42 +1300
Kent Fredric <kentfred...@gmail.com> wrote:

> On 14 March 2015 at 22:38, Manfred Lotz <manfred.l...@arcor.de> 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.
> 

You are right. I perceive it as an error I want to catch but in the
script it is actually a warning.

> However, curiously, "<:utf8" 's warnings seems to be regulated by the
> warnings pragma.
> 
> But "<:encoding(UTF-8)" is not.
> 
> 

I didn't want to scan stderr for this. So I hoped for a more elegant
way.

Thanks a lot.

-- 
Manfred


> ---
> 
> 
> use strict;
> use warnings;
> 
> ## make the file
> {
>   open my $fh, '>', './somefile';
>   print $fh chr(0x90);
>   close $fh;
> }
> ## read the file
> 
> {
>   *STDERR->print("Attempt 1\n");
> 
>   open my $fh, '<:utf8', './somefile';
> 
>   my $string = <$fh>;
> 
>   close $fh;
> }
> 
> {
>   *STDERR->print("Attempt 2\n");
>   open my $fh, '<:utf8', './somefile';
>   no warnings 'utf8';
> 
>   my $string = <$fh>;
> 
>   close $fh;
> }
> {
>   *STDERR->print("Attempt 3\n");
>   open my $fh, '<:encoding(UTF-8)', './somefile';
>   no warnings 'utf8';
> 
>   my $string = <$fh>;
> 
>   close $fh;
> }
> 
> ---
> 
> 
> The first and last of these warns, the middle does not.
> 
> Though all of the above can be captured with
> 
> local $SIG{__WARN__} = sub {
>     printf "<%s> @ %s\n", $_[0], join q[,], caller();
>  };
> 
> Whether or not that is recommended is a different question.
> 


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to